On my infinityfree free website I want to record the ip address of my visitors. Using the function below, when I access my site at home using different devices it always returns the same ip address - not the ip address of the device. How can I get the visitors ip address? Thanks in advance.
// Function to get the user IP address
function get_user_ip() {
$ipaddress = "";
if (isset($_SERVER['HTTP_CLIENT_IP'])):
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])):
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif(isset($_SERVER['HTTP_X_FORWARDED'])):
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
elseif(isset($_SERVER['HTTP_FORWARDED_FOR'])):
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
elseif(isset($_SERVER['HTTP_FORWARDED'])):
$ipaddress = $_SERVER['HTTP_FORWARDED'];
elseif(isset($_SERVER['REMOTE_ADDR'])):
$ipaddress = $_SERVER['REMOTE_ADDR'];
else:
$ipaddress = 'UNKNOWN';
endif;
return $ipaddress;
}
I have 2 PCs and a tablet, each has its own different ip address. Why does it always return the same address - or am I missing something. Is it the ip_address of my router? Thanks for your help by the way.
Thanks KangJL. I’ve got it now. Do me a favour and login to jagger.epizy.com. I’ve created a function to record all visitors. It’s working when I login but not known when somebody else logs in.