Getting the IP address using PHP

You can display the visitor's IP address on a webpage or you can use it for other purposes such as storing it for security (if you're running an e-commerce site), redirecting the visitor, even banning the visitor from your website if you need to.

Get IP address of a visitor

Use the REMOTE_ADDR index of the $_SERVER array to get the IP address of the visitor.

Your IP address is <?php echo $_SERVER['REMOTE_ADDR']; ?>
Your IP address is

Get IP address of a website

You can get the IP address of a website by it's URL. Include the URL as a parameter of the gethostbyname() function.

IP address of is <?php echo gethostbyname(''); ?>
IP address of is
© Copyright 2013-2014
Terms of use | Privacy policy | Copyright information