Login with Google account in CodeIgniter with OpenID

前端 未结 2 992
长发绾君心
长发绾君心 2020-12-14 04:06

I want to implement a login with a Google account using OpenID, but I have no idea how to start this procedure because I have no idea about how to do it. So is there any ste

2条回答
  •  天涯浪人
    2020-12-14 05:00

    At first download openid.php and put in your codeigniter root folder.

    1. copy the code and save as ..../controller/logingoogle.php

        load->model('login_model');
        }
    
        public function index()
        {
            require_once 'openid.php';
            $openid = new LightOpenID("localhost");
            $openid->identity = 'https://www.google.com/accounts/o8/id';
            $openid->required = array(
                'namePerson/first',
                'namePerson/last',
                'contact/email',
                'birthDate', 
                'person/gender',
                'contact/postalCode/home',
                'contact/country/home',
                'pref/language',
                'pref/timezone',  
            );
    //  $openid->returnUrl = 'http://localhost/login_thirdparty/login_google.php';
    
        $openid->returnUrl = 'http://localhost/login_thirdparty/codeigniterlogin/index.php/logingoogle/loginAuth';
    
    //  echo 'Login with Google';
    
            $data['openid'] = $openid;
            $this->load->view('googleLoginView', $data);
        }
    
        public function loginAuth()
        {
            $this->login_model->index();
        }
    }
    

    2. copy the code and save as ..../views/googleLoginView.php

    
    
    
        Login using google account
    
    
         Loging Using google account 
    
    
    

    3. copy the code and save as ..../models/login_model.php

    mode)
            {
                if($openid->mode == 'cancel')
                {
                    echo "User has canceled authentication !";
                }
                elseif($openid->validate())
                {
                    $data = $openid->getAttributes();
                    $email = $data['contact/email'];
                    $first = $data['namePerson/first'];
        //          header("Location: http://speechwithmilo.com/speechtherapy/adminpanel/");
                    echo "Identity : $openid->identity 
    "; echo "Email : $email
    "; echo "First name : $first"; echo "
    "; print_r($data); echo "
    "; // echo ""; } else { echo "The user has not logged in"; } } else { echo "Go to the login page to logged in"; } } }

提交回复
热议问题