简体   繁体   English

PHP:获取服务器的IP地址,用户单击该链接重定向到我的外部站点的链接

[英]PHP: Get IP address of server where user clicked a link redirecting to my external site

For clarity imagine this scenario: 为清楚起见,请想象一下

  • User is on siteA.com 用户在siteA.com上
  • User clicks on a link directing to my site: siteB.com 用户点击指向我网站的链接:siteB.com
  • My site wants to determine the IP address of siteA.com upon getting the request, so that it knows the IP of the server that linked to it for this request. 我的网站想要在获得请求时确定siteA.com的IP地址,以便它知道为此请求链接到它的服务器的IP。

Is there any way to do this with PHP and Apache? 有没有办法用PHP和Apache做到这一点? If not, is there any way at all to do this? 如果没有,有什么办法可以做到这一点吗?

<?php

// Perhaps something like:
$linking_server_ip = $_SERVER[LINKING_SERVER_IP];

?>

Edit: 编辑:

So $_SERVER['HTTP_REFERER'] can't be relied on, but I can use it casually I guess (supplemental/opportunistic info to indicate that a referrer isn't from an expected endpoint, if it's not empty maybe. Though it sounds like it's not reliable for even this much given that any plugin clientside could still mangle the value anyway, making a legit referral appear to be from some other server). 所以$ _SERVER ['HTTP_REFERER']不能依赖,但我可以随意使用它(补充/机会信息表明引用者不是来自预期的端点,如果它不是空的可能。虽然它听起来因为即使这样也是不可靠的,因为任何插件客户端仍然可以破坏价值,使得合法推荐似乎来自其他服务器)。

I'm still left with this problem: 我还有这个问题:

I need to verify that the server referring to a particular page on my site (which acts as a certificate for that server). 我需要验证服务器引用我站点上的特定页面(它充当该服务器的证书)。

EG Their page has a link to certificate.php?serverid=1234 EG他们的页面有一个指向certificate.php?serverid = 1234的链接

I want to verify that they're not cheating the system and using this certificate on any of their other servers (eg using siteA's certificate for siteC and avoiding paying for the service that's supposed to have been done on siteC as well). 我想验证他们没有欺骗系统并在其他任何服务器上使用此证书(例如,使用siteA的siteC证书并避免支付应该在siteC上完成的服务)。

Even with the crude solution of making the server of siteA http request my server (siteB) to get a one-time use token in order to be validated on certificate.php, they could just use siteA to grab a token each time their other sites need a token to be validated when so they can cheat validation and claim the certificate for siteA. 即使使用siteA http服务器的粗略解决方案请求我的服务器(siteB)获取一次性使用令牌以便在certificate.php上进行验证,他们也可以使用siteA每次其他站点时获取令牌需要一个令牌进行验证,以便他们可以欺骗验证并为siteA申请证书。

The HTTP Referer header (yes, that's how it's spelled!) tells you this. HTTP Referer标头(是的,这就是拼写的方式!)告诉你这个。 It's available in your PHP script as $_SERVER['HTTP_REFERER'] . 它在您的PHP脚本中可用作$_SERVER['HTTP_REFERER']

(But note that there's no guarantee that all browsers will provide it, and that it can be spoofed. Don't use it to enforce any security policies.) (但请注意,并不能保证所有浏览器都会提供它,并且它可以被欺骗。不要使用它来强制执行任何安全策略。)

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

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