我正在我的网站上实施谷歌openid脚本。主要有三个组成部分:
index.php,登录链接为:
<?php
session_start();
if (isset($_SESSION['UNAME']) && !(empty($_SESSION['UNAME']))){
echo '<a href="logout.php"><b><u>Logout</u></b></a><br/><br/>';
echo "Name:-".$_SESSION['UNAME']."<br/><br/>";
echo "Email:-".$_SESSION['UEMAIL'];
}else{
echo '<a href="login_process.php">Login With Gmail</a>';
}
?>
login_process.php,登录用户:
<?php
include('inc/lightopenid.php');
$callback_website_url='http://mysite/google_login/google_landing.php';
googleAuthenticate($callback_website_url);
function googleAuthenticate($callback_website_url) {
$openid = new lightopenid;
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->returnUrl = $callback_website_url;
$endpoint = $openid->discover('https://www.google.com/accounts/o8/id');
$fields ='?openid.ns=' . urlencode('http://specs.openid.net/auth/2.0') .
'&openid.return_to=' . urlencode($openid->returnUrl) .
'&openid.claimed_id=' .
urlencode('http://specs.openid.net/auth/2.0/identifier_select') .
'&openid.identity=' .
urlencode('http://specs.openid.net/auth/2.0/identifier_select') .
'&openid.mode=' . urlencode('checkid_setup') .
'&openid.ns.ax=' . urlencode('http://openid.net/srv/ax/1.0') .
'&openid.ax.mode=' . urlencode('fetch_request') .
'&openid.ax.required=' . urlencode('email,firstname,lastname') .
'&openid.ax.type.firstname=' .
urlencode('http://axschema.org/namePerson/first') .
'&openid.ax.type.lastname=' .
urlencode('http://axschema.org/namePerson/last') .
'&openid.ax.type.email=' . urlencode('http://axschema.org/contact/email');
header('location:'.$endpoint . $fields);
}
?>
google_landing.php,重定向到着陆页:
<?php
session_start();
include('inc/dbConnect.inc.php');
if (!empty($_GET['openid_ext1_value_firstname']) && !empty($_GET['openid_ext1_value_lastname']) && !empty($_GET['openid_ext1_value_email'])) {
$username = $_GET['openid_ext1_value_firstname'] . $_GET['openid_ext1_value_lastname'];
$email = $_GET['openid_ext1_value_email'];
$uname=$_GET['openid_ext1_value_firstname'].' '.$_GET['openid_ext1_value_lastname'];
$email=$_GET['openid_ext1_value_email'];
$checkUserSql="select * from google_login where email= '$email'";
$checkUserRes=mysql_query($checkUserSql);
$checkUserCount=mysql_num_rows($checkUserRes);
if($checkUserCount == 0){
$sql="insert into google_login(name,email,inserted_on) values('$uname','$email',now())";
mysql_query($sql);
}
$_SESSION['UNAME']=$_GET['openid_ext1_value_firstname'].' '.$_GET['openid_ext1_value_lastname'];
$_SESSION['UEMAIL']=$_GET['openid_ext1_value_email'];
}
header('location:../index.php');
?>
问题是,一旦用户登录并尝试从索引页面移动到任何其他页面,他就会再次遇到“使用Gmail登录”链接,而不是在页面之间传递会话然后显示他登录时登录了他的登录信息。
你能帮忙吗?感谢。编辑:这是我要从索引中移动到的页面:
圣经查询:
<?php ob_start(); ?>
<html>
<link rel="icon" type="image/png" href="/mybq-images/BQ.png">
<link rel="stylesheet" type="text/css" href="mystyle-a.css">
<title>BQuotes CMS: Random Bible Verse</title>
</head>
<body class='left'>
<div class='table1'>
<table width='100%'>
<col width='100'>
<col width='100'>
<col width='100'>
<tr><td><b>BQuotes Random Bible Verse</b></td></tr>
<tr><td>
<?php
session_start();
if ($_SESSION['timeout'] + 10 * 60 < time()) {
// session timed out
session_destroy();
//header("Location: mybq-logout.php");
}
$_SESSION['timeout'] = time();
// regular login begin
if (!(isset($_SESSION['myusername']) && $_SESSION['myusername'] != '')) {
echo "<div class='right'><a href='mybq-login.php'>Login </a></div>";
}
else {
echo "<div class='right'><a href='mybq-logout.php'>Logout </a>" . $_SESSION['myusername'] . "</div>";
// regular login end
}
?>
</td>
</tr>
<tr>
<td width='180'>
<div class='center2'>
<?php
$id = $_GET['id']; //get initial query from index
$db = new PDO('mysql:host=localhost;dbname=db;charset=utf8', 'username', 'password');
$stmt = $db->prepare('SELECT id,book,cap,verse,line FROM bible_kjv where id = ?');
if($stmt->execute(array($id))){
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo "<p>", ($row['book']), " ", ($row['cap']), " ", ($row['verse'])," <br>";
echo "<p>", ($row['line']), "<br>", "<br>";
}
}
?>
</div>
</td></tr>
<!--bible query new section begins-->
<tr><td>
<div class='center2'>
<?php
foreach($db->query("SELECT id,book,cap,verse,line FROM bible_kjv ORDER BY RAND() LIMIT 1") as $row) {
echo "<a href='bible-query.php?id=$row[id]'>New Verse</a> ";
}
?>
<!--bible query new section ends-->
<a href="https://twitter.com/share" class="twitter-share-button">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
<br>
</div>
</td></tr>
<tr><td>
<div class='center2'>
<a href = "index.php">CMS Index</a>
</div>
</td></tr>
<tr><td colspan='2'>
<div class='center2'>
<form method="get" action="bible-search.php">
<label>Search BIBLE For: </label><input type="text" name="query" />
<input type="submit" name="submit" value="Search" />
<input type="reset" value="Reset" />
</form>
<div class='tagtext'>E.G.: Deuteronomy 28, Deuteronomy 28 2, the Lord shall make thee the head</div>
</div>
</td></tr>
</table>
</body> </html>
<?php ob_flush(); ?>