PHP: Print out your users IP Adress
It is fairly easy to find out your clients IP address when using PHP. The PHP script is basically one single line and returns the IP address that can be accessed for example as String.
See the PHP code example below to find out how to receive the clients IP address.
echo "<b>Your IP address:</b> ".$_SERVER["REMOTE_ADDR"];
The code stated above creates the following output:
Your IP address: 220.127.116.11
The IP Adress may be used as a String. Regular expressions are a common way to deal with IP addresses in String representation.
If you are presenting you website in different languages you may use the IP address to find out the rough location of a visitor to present your contents accordingly.
To find out how the IP adresses are distributed geographically around the world take a look at the IANA: http://www.iana.org/
You still have questions?
Feel free to use our comment form that is also available for non-registered users.