Php 使用OpenID在CodeIgniter中使用Google帐户登录
我想用OpenID实现一个Google帐户的登录,但是我不知道如何开始这个过程,因为我不知道如何做。因此,有没有任何一步一步的指南,以便我可以轻松地实现一个谷歌帐户登录与PHP中的CodeIgniter 我只找到了,但我不能正确理解它,所以有任何指南或任何图书馆登录谷歌帐户 下载。创建login.php文件,并将以下代码粘贴到该文件中Php 使用OpenID在CodeIgniter中使用Google帐户登录,php,codeigniter,openid,Php,Codeigniter,Openid,我想用OpenID实现一个Google帐户的登录,但是我不知道如何开始这个过程,因为我不知道如何做。因此,有没有任何一步一步的指南,以便我可以轻松地实现一个谷歌帐户登录与PHP中的CodeIgniter 我只找到了,但我不能正确理解它,所以有任何指南或任何图书馆登录谷歌帐户 下载。创建login.php文件,并将以下代码粘贴到该文件中 <?php require_once 'openid.php'; $openid = new LightOpenID("my-domain.com");
<?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.";
}
<?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>
这就是你需要做的一切。该代码在第一次下载时取自。,并放在codeigniter根文件夹中
1。复制代码并另存为..../controller/logingoogle.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class LoginGoogle extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->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 '<a href="'.$openid->authUrl().'">Login with Google</a>';
$data['openid'] = $openid;
$this->load->view('googleLoginView', $data);
}
public function loginAuth()
{
$this->login_model->index();
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login using google account</title>
</head>
<body>
<a href = "<?php echo $openid->authUrl(); ?>" > Loging Using google account </a>
</body>
</html>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require 'openid.php';
class Login_model extends CI_Model
{
public function index()
{
$openid = new LightOpenID("localhost");
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'];
// header("Location: http://speechwithmilo.com/speechtherapy/adminpanel/");
echo "Identity : $openid->identity <br />";
echo "Email : $email <br />";
echo "First name : $first";
echo "<pre>"; print_r($data); echo "</pre>";
// echo "<meta http-equiv = 'refresh' content = '0; url=http://speechwithmilo.com/speechtherapy/adminpanel/'>";
}
else
{
echo "The user has not logged in";
}
}
else
{
echo "Go to the login page to logged in";
}
}
}
谢谢,但我得到了电子邮件和用户名之类的数据,但不是每次只得到电子邮件和语言,我使用openid.php文件中的define之类的所有参数,但没有得到任何其他参数下载登录openid不起作用。你能给出任何其他URL吗?我使用了你的解决方案,但遇到了一个错误。请看一下我的问题。请注意,自2015年4月以来,谷歌停止使用OpenID登录,转而使用OpenID Connect登录,这是一个完全不同的继任者,另请参见: