从 file_get_contents 请求获取 IP
我有两个页面,一个发送 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当您在请求中传递 IP 时:
Only if you will pass IP in request: