简体   繁体   English

验证点击是否来自特定网站

[英]Verifying that the click came from the specific website

I'm building a custom authentication process where each user who came by clicking the link (containing unique hash) at the website B is automatically logged in on website A. The login process is not a question.我正在构建一个自定义身份验证过程,其中通过单击网站 B 上的链接(包含唯一哈希)来的每个用户都会自动登录到网站 A。登录过程不是问题。

The question is about security: how to ensure that the user came from the specific website and not from any other?问题是关于安全性:如何确保用户来自特定网站而不是来自其他任何网站? I can validate a variable $_SERVER['HTTP_REFERER'] but it can be easily spoofed.我可以验证变量$_SERVER['HTTP_REFERER']但它很容易被欺骗。 Is there a way to get the referrer IP (not the client machine IP which is in the $_SERVER array) or any other way to secure this process?有没有办法获得引荐来源 IP(不是$_SERVER数组中的客户端机器 IP)或任何其他方式来保护这个过程?

Suggestion 1建议一

When the link is clicked on the first website store the time and user ip in a database.当在第一个网站上单击链接时,将时间和用户 ip 存储在数据库中。

When the user request is then made on the second website it can take the time and user ip and ask the first website if the link was clicked by that ip recently.然后在第二个网站上发出用户请求时,它可能需要时间和用户 ip 并询问第一个网站是否最近点击了该链接 ip。

Suggestion 2建议二

The link on the client's site could link to a page on their site that uses PHP's file_get_contents() to show the linked page.客户站点上的链接可以链接到他们站点上的一个页面,该页面使用 PHP 的file_get_contents()来显示链接的页面。 Because it was PHP that requested the linked page a user can't spoof the document.referrer.因为请求链接页面的是 PHP,所以用户无法欺骗 document.referrer。 I have no idea how this would affect cookies, external references and the like.我不知道这将如何影响 cookies、外部参考等。

It definitely breaks relative links.它肯定会破坏相对链接。

Change the link from将链接从

`<a href="https://your-website.com/page/to/link/to">Click Here</a>`

to

`<a href="https://client-website.com/special-page?linked-page-url=https://your-website.com/page/to/link/to">Click Here</a>`

Special page on client's website:客户网站上的特殊页面:

<?php
$linkedPageUrl = $_GET['linked-page-url'];
var_dump(file_get_contents($linkedPageUrl));
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM