We can easily get IP Address of visitor with php environment variables .User IP Address was stored in following php Environment variables $_SERVER['REMOTE_ADDR'],$_SERVER['HTTP_CLIENT_IP'] and $_SERVER['HTTP_X_FORWARDED_FOR'].
most common practice for to get IP address of visitor with php is
2 |
$ip = $_SERVER [ 'REMOTE_ADDR' ]; |
3 |
echo 'User ip Address' . $ip ; |
We can’t trust above script generated ip address if user use proxy sever it simple return proxy IP.So to get user’s real IP address we should check for proxy and shared servers first.i have wrote one php function to get real IP address of visitor.
03 |
if (isset( $_SERVER [ 'HTTP_CLIENT_IP' ])) // check for shared servers |
05 |
$ip = $_SERVER [ 'HTTP_CLIENT_IP' ]; |
07 |
elseif (isset( $_SERVER [ 'HTTP_X_FORWARDED_FOR' ])) // check for proxy servers |
09 |
$ip = $_SERVER [ 'HTTP_X_FORWARDED_FOR' ]; |
11 |
$ip = $_SERVER [ 'REMOTE_ADDR' ]; // general method |
13 |
list( $ip ) = explode ( ',' , $ip ); |
16 |
echo GetUserIp(); // print ip address |
No comments:
Post a Comment