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