How To Get IP Address in PHP

Last Updated 2/23/2017

Get the visitor's IP address in PHP

Whenever a browser sends a request for a page, it also sends a number of other headers to the script, containing information such as the browser type. It also includes information such as the visitors IP address.

The following PHP script will display the visitor’s IP:

<?php
// Use getenv()
echo getenv('REMOTE_ADDR');

// Or use a Superglobal ($_SERVER or $_ENV)
echo $_SERVER['REMOTE_ADDR'];
?>


To find sample programming code and tutorials how to get the visitor's IP address in ASP, ASP.NET, C#, VB.NET, JAVA, JavaScript and Perl check here: