dqoeghe9452 2012-03-22 03:19
浏览 24
已采纳

我怎么知道用户真的使用OpenID登录或只是粘贴上一次登录的URL?

I have two pages: login.php and return.php. Both use LightOpenID.

The page login.php creates a link to an OpenID provider and tells the provider to return the result to return.php

The following are the normal flow of using those two pages.

  1. Go to login.php and click the link.
  2. Login using a Google account.
  3. The system redirects to return.php and shows that User ... has logged in.

However, later on, I can make return.php says the same thing even I don't do Step 2 by pasting the URL of return.php with its query string (copy from Step 3).

How can I know that a user really login using OpenID or just paste the URL from the previous login?

Here are the code:

login.php

<?php
require_once 'openid.php';

$openid = new LightOpenID("mydomain.com");
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->returnUrl = 'http://mydomain.com/return.php'
?>

<a href="<?= $openid->authUrl() ?>">Login</a>

return.php

<?php
require_once 'openid.php';

$openid = new LightOpenID("mydomain.com");
if($openid->mode) {
  echo 'User ' . ($openid->validate() ? $openid->identity .  ' has ' : 'has not ') . 'logged in.';
} elseif($openid->mode == 'cancel') {
  echo 'User has canceled authentication!';
} else {
  echo 'Please go to login.php';
}
?>
  • 写回答

2条回答 默认 最新

  • duanaigua4033 2012-03-23 09:19
    关注

    $openid->validate() will return true only once per authentication. If an user attempts to login again using the exact same url (i.e. same nonce, etc.), $openid->validate() will return false. At least that's the case if the provider works according to the spec. If it doesn't, there's almost nothing you can do.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog