0

Using this code:

On server A I have this:

$handle = fopen('http://www.server_b.com/get_ip.php', 'r'); //This is just a PHP file that echoes the REMOTE_ADDR
echo "IP looks like ".fread($handle, '100000')." to external server.\n";
fclose($handle);
echo "IP looks like ".$_SERVER['SERVER_ADDR']." to this server.";

on server B I have this:

echo $_SERVER['REMOTE_ADDR'];

I'm getting the following output from server A:

IP looks like xxx.xxx.223.90 to external server. //xxx.xxx on both lines are the same
IP looks like xxx.xxx.223.94 to this server.

Why am I getting two different IPs? Note, we do own the IP range from .90-.94

HellaMad
  • 5,294
  • 6
  • 31
  • 53

1 Answers1

1

Since it's a VPS, what you're probably seeing on server_b is the IP address of the host machine of the VPS that server_a is running on.

Either that, or there's some other proxying mechanism going on.

There may be a way around this:

Do a print_r() of $_SERVER on server_b.

Depending on the config of the various servers involved, in addition to the REMOTE_ADDR you may also get a value like $_SERVER['HTTP_FORWARDED']. This will be the IP address of the originating machine being passed on by the proxy, and should be the one you're expecting.

This question may help you further: What is the most accurate way to retrieve a user's correct IP address in PHP?

Community
  • 1
  • 1
SDC
  • 14,192
  • 2
  • 35
  • 48