检测域更改?

发布于 2024-11-16 07:22:42 字数 180 浏览 2 评论 0原文

是否可以检测网络转发的来源?

例如, 域 A 重定向到 域 B,其中域 B 有 PHP 托管?

基本上我想要类似以下的东西:

if ($was_redirected_from_domain_a) { ... }

Is it possible to detect source of web forwarding?

For example,
Domain A redirects to Domain B where Domain B has PHP hosting?

Basically I would like something like the following:

if ($was_redirected_from_domain_a) { ... }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

贱人配狗天长地久 2024-11-23 07:22:42

正如 @MoarCodePlz 和 @Christopher Armstrong 指出的,$_SERVER["HTTP_REFERER"] 是解决方案。

但是,在您的具体情况下,会发生两次重定向:

http: //fhc.quickmediasolutions.com/image/-1457172086.png

这样,原始的引荐来源网址信息就会丢失。您需要禁用第二个重定向,并在 my-art-gallery.co.uk 的索引页面中运行 PHP。

看到 phpinfo() 输出后更新:

$_SERVER["HTTP_REFER"] 确实完全不存在。

我怀疑罪魁祸首是这个配置设置:

suhosin.server.strip = On 

您的托管公司正在运行 Suhosin PHP 补丁,该补丁允许从 PHP 页面中删除某些数据以增强安全性。您可能需要要求他们激活 HTTP_REFERER。

唯一的其他方法是将域 A 重定向到类似的内容,

domainb.co.uk/index.php?camefrom=domainA

然后您可以通过 $_GET["camefrom"] 获取domainA 参数 - 如果托管提供商的控制面板允许这种重定向。

As @MoarCodePlz and @Christopher Armstrong point out, $_SERVER["HTTP_REFERER"] is the solution.

However, in your specific case, two redirects take place:

http://fhc.quickmediasolutions.com/image/-1457172086.png

This way, the original referrer info is lost. You will need to disable the second redirect, and run your PHP in my-art-gallery.co.uk's index page.

Update after seeing the phpinfo() output:

$_SERVER["HTTP_REFER"] is indeed completely non-existent.

I suspect the culprit is this configuration setting:

suhosin.server.strip = On 

your hosting company is running the Suhosin PHP patch, which allows removing certain data from the PHP page for enhanced security. You may need to ask them to activate HTTP_REFERER.

The only other way would be redirecting domain A to something like

domainb.co.uk/index.php?camefrom=domainA

You could then fetch the domainA argument through $_GET["camefrom"] - if the hosting provider's control panel allows that sort of redirection.

孤独患者 2024-11-23 07:22:42

您需要查看的内容称为页面的 url 引用者。 url 引荐来源网址是当前用户访问该网站的 url。但要小心,因为如果用户打开选项卡并简单地输入 url,则 url 引荐来源网址将不存在。

应该能够使用以下命令找到 url 引用:

$myVar = $_SERVER['HTTP_REFERER'];

What you need to look at is known as the url referrer of the page. The url referrer is the url from which the current user made it to the site. Be careful, though, as the url referrer will be nonexistent if the user opened up a tab and simply typed in the url.

The url referrer should be able to be found using the following:

$myVar = $_SERVER['HTTP_REFERER'];
毁梦 2024-11-23 07:22:42

正如 Pekka 所说,这取决于用户的转发方式。尝试检查 $_SERVER['http_referrer'] 值:

if ($_SERVER['HTTP_REFERER'] == 'mydomain.com/mypage'){
    echo 'Came from mydomain';
}

As Pekka said, it depends on how the user was forwarded. Try checking the $_SERVER['http_referrer'] value:

if ($_SERVER['HTTP_REFERER'] == 'mydomain.com/mypage'){
    echo 'Came from mydomain';
}
三生路 2024-11-23 07:22:42

$_SERVER["HTTP_REFERER"] 不是一个可靠的解决方案。在不同的情况下它不起作用。

HTTP_REFERER 不包含重定向页面的 URL,而是包含用户单击的页面的 URL。

例如,在页面 example.com 上有一个指向 t.co/somelink< 的链接/code>,重定向到 yoursite.com。
$_SERVER["HTTP_REFER"] 将包含 http://example.com,并且无法知道您的访问者是通过 Twitter 短视频重定向到您的网站的网址。

知道用户来自您的 Twitter 链接的唯一方法是包含 $_GET 参数,就像已经建议的那样:让链接 t.co/somelink 重定向到yoursite.com/?camefrom=twitter

$_SERVER["HTTP_REFERER"] is not a reliable solution. There are different cases where it does not work.

HTTP_REFERER does not contain the URL of the page that redirected, but the URL of the page where the user clicked.

E.g. On the page example.com is a link to t.co/somelink, which redirects to yoursite.com.
$_SERVER["HTTP_REFER"] will contain http://example.com, and there is no way to know that your visitor was redirected on your site from a twitter short URL.

The only way to know that the user came from your twitter link, is to include a $_GET parameter, like already proposed: Let the link t.co/somelink redirect to yoursite.com/?camefrom=twitter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文