我制作了一个用户使用谷歌登录的网站,在那里会打开一个弹出窗口进行登录,当用户单击提交按钮时,弹出窗口关闭&用户重定向到另一个页面。
我已经完成了代码,但它在FF bt中工作良好,而在chrome 中不工作
这是我的代码,有人能建议我需要做什么更改吗?这样它也能在chrome中工作。
<?php
@session_start();
require 'openid.php';
try {
$openid = new LightOpenID;
if(!$openid->mode) {
if(isset($_GET['login'])) {
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->required = array('namePerson/first', 'namePerson/last', 'contact/email');
// @header('Location: ' . $openid->authUrl());
echo "<script>location.href='".$openid->authUrl()."'</script>";
}
} elseif($openid->mode == 'cancel') {
echo 'User has canceled authentication!';
} else {
if($openid->validate())
{
'User <b>' . $openid->identity . '</b> has logged in.<br>';
"<h3>User information</h3>";
$_SESSION['identity'] = $openid->identity;
$identity = $openid->identity;
$attributes = $openid->getAttributes();
$_SESSION['email'] = $attributes['contact/email'];
$_SESSION['first_name'] = $attributes['namePerson/first'];
$_SESSION['last_name'] = $attributes['namePerson/last'];
/* "mode: " . $openid->mode . "<br>";
"identity: " . $identity . "<br>";
"email: " . $email . "<br>";
"first_name: " . $first_name . "<br>";
"last_name: " . $last_name . "<br>";*/
}
else
{
echo 'User ' . $openid->identity . 'has not logged in.';
}
echo "<script>window.close();</script>";
echo '<script>window.opener.location.href="index2.php"</script>';
}
} catch(ErrorException $e) {
echo $e->getMessage();
}
?>
我相信window.close((在chrome中不适合您。一旦我遇到这个问题,我就用解决了这个问题
替换window.close((;代码低于
window.open('', '_self', ''); //simple bug fix
window.close();
也试着把这个
echo '<script>window.opener.location.href="index2.php"</script>';
echo "<script>window.open('', '_self', '');window.close();</script>";
希望它也适用于你。
如果没有,请更具体地说明问题
请尝试下面的任何一个选项
echo('opener.window.location.reload(true(;window.close((;'(;或echo('window.oopener.location.reload(false(;window.close((;'(;
如果仍然存在问题,请告诉我