简体   繁体   English

获取PHP中的推荐站点IP地址

[英]Get referring site IP address in PHP

I want to implement a referral program for my SaaS product. 我想为我的SaaS产品实现推荐计划。

The partner will have a link on their website that will direct their user to my signup form: 合作伙伴将在其网站上提供一个链接,该链接会将其用户引导至我的注册表单:

domain.com/referral/201030

"201030" being the member id from the partner site. “ 201030”是合作伙伴站点的成员ID。

I want to make sure the page request came from my partner site, 我想确保页面请求来自我的合作伙伴网站,

I know I could check $_SERVER['HTTP_REFERER'] but that is not secure. 我知道我可以检查$_SERVER['HTTP_REFERER']但这并不安全。

Is there a way I can check the IP address of the site referring the user to my webpage with PHP? 有什么方法可以检查使用PHP将用户引到我的网页的网站的IP地址吗?

When do you need high security? 什么时候需要高安全性?

For an API for example, you want to track the incoming traffic and make sure only authenticated clients can access the API. 例如,对于一个API,您要跟踪传入的流量,并确保只有经过身份验证的客户端才能访问该API。 This needs higher security standards and exchange of public keys and secrets. 这需要更高的安全标准以及公共密钥和秘密的交换。

When not? 什么时候不?

A referral program doesn't need this kind of security. 推荐程序不需要这种安全性。

The more traffic you have, the better for you. 您拥有的流量越多,对您越有利。 You don't care where the lead is coming from. 您不在乎潜在客户来自何处。 When I send my partner program link to someone via messenger, there is not even a HTTP_REFERER. 当我通过Messenger发送我的合作伙伴程序链接给某人时,甚至没有HTTP_REFERER。

Is it even possible? 可能吗

It is very difficult impossible to make sure where the user is coming from without serverside interaction, obfuscation and dynamic links. 没有服务器端的交互,混淆和动态链接, 很难 确保用户来自哪里。

Any chance? 任何机会?

The only way, using a static link, is $_SERVER['HTTP_REFERER'] . 使用静态链接的唯一方法是$_SERVER['HTTP_REFERER'] You can downvote the answer now, but it doesn't change the fact that there is no way, with a simple, non-dynamic link like shown in the question. 您现在可以对答案进行投票表决,但不会改变事实,即没有简单的,非动态的链接(如问题所示)的事实。

Turn the referer into an IP 将引荐来源转化为IP

To turn the HTTP_REFERER into an IP: 要将HTTP_REFERER转换为IP:

$urlParts = parse_url($_SERVER['HTTP_REFERER']);
$ip       = gethostbyname($urlParts['host']);

Keep in mind, this is not reliable nor secure in any way. 请记住,这在任何方面都不可靠也不安全。

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

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