How to get IP address of visitor in PHP

Getting the IP address of the visitor is the simplest task in PHP.Look at the following example:

echo $userIP;

This should print something like following if you are working in wamp server or any local environment.
All the magic is done by the PHP superglobal $_SERVER.The REMOTE_ADDR is just another element of $_SERVER superglobal whcich retrieves the IP of the user computer.Note that this IP sometimes may be the IP of the LAN, the user is connected with.



Post a Comment