我有两个页面,其中一个发送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)
我在哪里可以找到发送请求的计算机上的更多信息?
提前感谢!
仅当您在请求中传递IP时:
$registration_key = file_get_contents('http://example.com/register.php?ip='.$_SERVER['REMOTE_ADDR'], false, $context);