How to Get Real IP from Visitor
- Article
- Comment
How to Get Real IP from Visitor. Sometimes, we need to keep track the visitors location, or we need to know the users location with help of IP Address to work a site based on the Visitors location with help of PHP.
function kv_get_user_ip_address(){ if(filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) return @$_SERVER['HTTP_CLIENT_IP']; elseif(filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) return @$_SERVER['HTTP_X_FORWARDED_FOR']; elseif(filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP)) return $_SERVER['REMOTE_ADDR']; } echo kv_get_user_ip_address();