Vishmax.com
Read

How to get client’s IP address in PHP

We design and develop websites, digital experiences, and software solutions for growing businesses.

Some times you need to track the visitors IP address for a particular reason. Here is some PHP codes which is usfun for those projects which needs to track IP address.

What is your IP Address

<?php
$ipaddress=@$REMOTE_ADDR; 
echo "Your IP Address is : = $ipaddress";
?>

The above code will display your IP address.

Function

<?php
//Return the visitor's IP address
function get_ip(){
 if (isset($_SERVER["REMOTE_ADDR"]))
 { 
 $ip=$_SERVER["REMOTE_ADDR"] . ' '; 
 } else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) { 
 $ip=$_SERVER["HTTP_X_FORWARDED_FOR"] . ' '; 
 } else if ( isset($_SERVER["HTTP_CLIENT_IP"]) ) { 
 $ip=$_SERVER["HTTP_CLIENT_IP"] . ' '; 
 }
 return $ip;
}
?>