1

所以,我有两个站点,站点 A 和 B。我需要使 B 成为 A 的一部分。我通过向 A 添加一个模块来做到这一点,并在该模块中添加一个包含指向 B 的链接的 iframe。所以,有效地说, B 仍然可以作为独立站点访问,但也可以通过 A 访问。现在,两个站点都需要登录才能访问。当通过站点 A 访问站点 B 时,我需要绕过它的登录。我设法绕过它,但前提是这两个站点托管在同一台服务器上(我使用了会话变量),但现在我需要能够无论托管在哪个服务器上,都绕过 B 上的登录屏幕。那么,我该怎么做呢?

起初我以为是 cookie,但 cookie 是特定于域的,这两个站点可能托管在不同的域上。

有没有办法使用GET?因此,站点 A 使用 url 中写入的用户名调用 url,然后站点 B 读取 url,对其进行解析并相应地登录。我不知道如何实现这一点,我必须调用什么样的 url,站点 B 需要什么样的 php 代码,最后,你如何确保这样的安全?

感谢你的帮助。

4

1 回答 1

1

Send a UUID with a hash to site B. The hash should be something that only both servers will know and can decode so something like the following should work.

On site A

<?php
$salt = 'ashfiu8435t43434t fgfjgfgfuguSGDSBDY77;';
$uuid = ''; // this should be set to the users ID
$hash = sha1($salt . $uuid);
?>
<a href="http://siteb.com?hash=<?php echo ($hash); ?>&uuid=<?php echo $uuid; ?>">Site B</a>

On site B

<?php
$salt = 'ashfiu8435t43434t fgfjgfgfuguSGDSBDY77;';
$uuid = $_GET['uuid'];
$sent_hash = $_GET['hash'];
$local_hash = sha1($salt . $uuid);

if($sent_hash === $local_hash) {
   echo 'Logged in! Yay!';
} else {
   echo 'Authentication failed';
}

You should make the hash more difficult to fake or figure out and make it expire after a given time so that people can't just save hashes and re-use them or pass them about. I have deliberately kept it simple to show this would work.

于 2011-09-19T16:24:56.737 回答