I want to know if there is a function that I can know the IP of a user.
For HTTP_REFERER, I can get the URL from the user such as http://www.sony.com.
BUT is there any way I can also know the IP of that?
thanks.
IP lookup or HTTP referer
Moderator: General Moderators
Code: Select all
$ip = getenv ("REMOTE_ADDR"); // get the ip number of the userCross-version function for retrieving the IP address w/ hostname cleanup 
Code: Select all
<?php
/*
kriek at jonkriek dot com
*/
function getIP() {
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
return $_SERVER['REMOTE_ADDR'];
}
} else {
if (isset($GLOBALS['HTTP_SERVER_VARS']['HTTP_X_FORWARDER_FOR'])) {
return $GLOBALS['HTTP_SERVER_VARS']['HTTP_X_FORWARDED_FOR'];
} else {
return $GLOBALS['HTTP_SERVER_VARS']['REMOTE_ADDR'];
}
}
}
$user = getIP();
$fullhost = gethostbyaddr($user);
$host = preg_replace("/^[^.]+\./", "*.", $fullhost);
?>
Your IP address is <?=$user?> | Your host is <?=$host?>Your IP address is 24.26.91.100 | Your host is *.tampabay.rr.com