Hi i need to trace the ip address of my visitors when they login; i found a function getenv("REMOTE_ADDR"); PHP: but when i uploaded a file having this function and ran on my computer i got my ip address: 202.165.255.17 but at the same time i checked ipconfig in cmd and it gave me a different ip: 202.165.254.118 what is the reason that ip address is not correctly given by the function or i should use some other function;
it may be; i am using dialup and on other isp i get the correct ip address; but with the previous isp my hosting CPanel is showing my correct ip address; what may be the reason...
I have found another funtion which is better in some situations; so i am using the two functions with conditional logic ; two functions i am using are: $_SERVER['HTTP_X_FORWARDED_FOR'] PHP: and $_SERVER['REMOTE_ADDR'] PHP:
here you go a super duper function for you /*** FUNCTION GETIP ***/ function getip() { if (isSet($_SERVER)) { if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) { $realip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } else if (isSet($_SERVER["HTTP_CLIENT_IP"])) { $realip = $_SERVER["HTTP_CLIENT_IP"]; } else { $realip = $_SERVER["REMOTE_ADDR"]; } } else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $realip = getenv( 'HTTP_X_FORWARDED_FOR' ); } else if ( getenv( 'HTTP_CLIENT_IP' ) ) { $realip = getenv( 'HTTP_CLIENT_IP' ); } else { $realip = getenv( 'REMOTE_ADDR' ); } } return $realip; } /*** FUNCTION GETIP ***/ PHP:
$_SERVER['REMOTE_ADDR'] works fine for my codes. Have you gave it a try. There's also another command i don't remember it right now but it is like HTTP_REFERER or something. You might find it on google.
hmmmm... really super, but It's necessary to TRACE user, and you'll get 192.168.255.22 from X_FORWARDED_FOR. Better store all. function getip() { $ip = array_unique(array('',$_SERVER["REMOTE_ADDR"],$_SERVER["HTTP_X_FORWARDED_FOR"],$_SERVER["HTTP_CLIENT_IP"])); array_shift($ip); return(implode(',',$ip)); } PHP: