Why does $_SERVER['REMOTE_ADDR'] return the gateway ip rather than the remote ip with a fortigate router?

StackOverflow https://stackoverflow.com/questions/19024616

  •  29-06-2022
  •  | 
  •  

Question

I have a server connected to the internet through a Fortigate 40C. When my php code calls $_SERVER['REMOTE_ADDR'], it returns the ip address of the router (the fortigate) rather than the remote IP accessing the php script.

Why is this?

Était-ce utile?

La solution

The Fortigate has an option to "enable NAT" on a policy, which doesn't mean translate the addresses (it does that for you anyway), but does mean it alters some packets replacing the remote IP with the gateway IP.

Make sure that "Enable NAT" is disabled, and $_SERVER['REMOTE_ADDR'] will work as expected.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top