Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

php - Login with Google account in CodeIgniter with OpenID

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 step by step guides for this so that I can easily implement a Google account login with CodeIgniter in PHP.

I've found only this but I cant understand it properly so is there any guides or any libraries to login with a Google account?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Download LightOpenID. Create the login.php file, and paste the following code into the file.

<?php

require_once 'openid.php';
$openid = new LightOpenID("my-domain.com");

if ($openid->mode) {
    if ($openid->mode == 'cancel') {
        echo "User has canceled authentication !";
    } elseif ($openid->validate()) {
        $data = $openid->getAttributes();
        $email = $data['contact/email'];
        $first = $data['namePerson/first'];
        echo "Identity : $openid->identity <br>";
        echo "Email : $email <br>";
        echo "First name : $first";
    } else {
        echo "The user has not logged in";
    }
} else {
    echo "Go to index page to log in.";
}

Create the index.php file, and paste the following code into the file.

<?php

require_once 'openid.php';
$openid = new LightOpenID("my-domain.com");

$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->required = array(
    'namePerson/first',
    'namePerson/last',
    'contact/email',
);
$openid->returnUrl = 'http://my-domain.com/login.php'
?>

<a href="<?php echo $openid->authUrl() ?>">Login with Google</a>

This is all you need to do. The code has been taken from Google Login with LightOpenID.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...