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 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探