从 file_get_contents 请求获取 IP

发布于 2024-11-02 01:21:01 字数 872 浏览 6 评论 0原文

我有两个页面,一个发送 file_get_contents 请求:

$postdata = http_build_query( array('install' => 'true', 'url' => $_SERVER['SERVER_NAME'], 'key' => 'XXXXXXXXXXXX') );

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);
$registration_key = file_get_contents('http://example.com/register.php', false, $context);

另一个页面接收调用(http://example.com/register.php),我试图获取请求来源的 IP,但无济于事。我已经尝试过:

$_SERVER['HTTP_CLIENT_IP']

$_SERVER['HTTP_VIA']

$_SERVER['HTTP_X_FORWARDED_FOR']

$ _SERVER['REMOTE_ADDR'] (IP,但不是发送或接收请求的计算机的 IP)

知道在哪里可以找到有关发送请求的计算机的更多信息吗?

提前致谢!

I have two pages, one sending a file_get_contents request:

$postdata = http_build_query( array('install' => 'true', 'url' => $_SERVER['SERVER_NAME'], 'key' => 'XXXXXXXXXXXX') );

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);
$registration_key = file_get_contents('http://example.com/register.php', false, $context);

And a page that receives the call (http://example.com/register.php) and I am trying to grab the IP of where the request is coming from to no avail. I have tried:

$_SERVER['HTTP_CLIENT_IP']

$_SERVER['HTTP_VIA']

$_SERVER['HTTP_X_FORWARDED_FOR']

$_SERVER['REMOTE_ADDR'] (IP, but not the IP of the computer sending OR receiving the request)

Any idea as to where I can find more info on the computer sending the request?

Thanks in advance!

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

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

发布评论

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

评论(1

感性 2024-11-09 01:21:01

仅当您在请求中传递 IP 时:

$registration_key = file_get_contents('http://example.com/register.php?ip='.$_SERVER['REMOTE_ADDR'], false, $context);

Only if you will pass IP in request:

$registration_key = file_get_contents('http://example.com/register.php?ip='.$_SERVER['REMOTE_ADDR'], false, $context);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文