Computer-Masters.net > Articles > Programming > PHP > PHP: Get your readers or users IP adress with a single PHP statement

PHP: Print out your users IP Adress

PHP Ip Address REMOTE_ADDR

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.


PHP-Script

<?php
    
echo "<b>Your IP address:</b> ".$_SERVER["REMOTE_ADDR"];
?>
1

The code stated above creates the following output:

Your IP address: 54.166.157.192

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.

The Terms of Use and Posting Guidelines apply.

 

Comments

Computer-Masters.net > Articles > Programming > PHP > PHP: Get your readers or users IP adress with a single PHP statement

Advertisement: