2

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!

RANGER
  • 1,643
  • 2
  • 17
  • 31
  • If you are already using `_context_create` you could just augment the `'header' =>` with `"\nX-Forwarded-For: $_SERVER[REMOTE_ADDR]"` so you'll receive it in the register.php script as the expected `$_SERVER['HTTP_X_FORWARDED_FOR']`. – mario Apr 15 '11 at 22:59

1 Answers1

4

Only if you will pass IP in request:

$registration_key = file_get_contents('http://example.com/register.php?ip='.$_SERVER['REMOTE_ADDR'], false, $context);
OZ_
  • 12,492
  • 7
  • 50
  • 68