使用 OpenID 在 CodeIgniter 中使用 Google 帐户登录 [英] Login with Google account in CodeIgniter with OpenID
问题描述
我想使用 OpenID 使用 Google 帐户实现登录,但我不知道如何开始此过程,因为我不知道如何进行.那么是否有任何分步指南,以便我可以轻松地在 PHP 中使用 CodeIgniter 实现 Google 帐户登录.
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.
我只找到了this,但我无法正确理解它,所以是否有任何指南或使用 Google 帐户登录的任何图书馆?
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?
推荐答案
下载 LightOpenID.创建 login.php 文件,并将以下代码粘贴到文件中.
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.";
}
创建 index.php 文件,并将以下代码粘贴到文件中.
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>
这就是您需要做的所有事情.代码取自 使用 LightOpenID 的 Google 登录.
This is all you need to do. The code has been taken from Google Login with LightOpenID.
这篇关于使用 OpenID 在 CodeIgniter 中使用 Google 帐户登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!