简体   繁体   English

PHP HTTP推荐人

[英]PHP HTTP Referrer

I have a page which accepts POSTs from a remote site. 我有一个页面接受来自远程站点的POST。 I would like to detect the domain that these POSTs are coming from. 我想检测这些POST来自哪个域。 I realize that it can be spoofed but it is better than nothing. 我意识到它可以被欺骗,但它总比没有好。 I have tried accessing the HTTP_REFERER variable but it just returns null. 我试过访问HTTP_REFERER变量,但它只返回null。

The page accepts POSTs from sources like PayPal (instant payment notifications) and other payment gateways. 该页面接受来自PayPal(即时付款通知)和其他支付网关等来源的POST。

How can I get the referring call? 我如何获得推荐电话?

You spelled Referer correctly. 你正确地拼写了Referer。 It should be: 它应该是:

$_SERVER['HTTP_REFERER']
$_SERVER['HTTP_REFERER'] 

使用单个R,尝试使用var_dump($ _ SERVER)获取更多信息。

This works for me pretty well: 这对我很有用:

https://stackoverflow.com/a/17958676/2635701 https://stackoverflow.com/a/17958676/2635701

<form action="http://www.yourdomain.com/subscribe" 
   method="POST" 
   onsubmit=
      "document.getElementById('www.yourdomain.com.referrer').value=window.location;" >
    <!-- hidden input for field starts with a domain registered by you 
    just so that it's unlikely to clash with anything else on the page -->
    <input type="hidden" id="www.yourdomain.com.referrer" name="referrer"/>
    your email: <input name="email" type="text"/>
    ... rest of form ...
    <input type="submit" value="Subscribe"/>
</form>

You are right that the referrer is easy to spoof, however there is a better solution. 你是好的,推荐人很容易欺骗,但有一个更好的解决方案。 Read the ipn documentation in which they mention validation mechanisms. 阅读他们提到验证机制的ipn文档 Never trust the user. 永远不要相信用户。

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

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