How to get client IP Address in PHP
How to get client IP Address in PHP, if you want to get ip address in php the simplest way use to remote address server super global. But this is not the best way to do is using different server super global functions, http client IP and http x forwarded for, remote address. By using these three functions we can get correct ip address of a client or computer who is accessing your website.
By using this single line of function you can get client IP address in php.[php] // Get the client IP address
$ip = $_SERVER[‘REMOTE_ADDR’] [/php]
But this is not the best way to php get client IP address, we can use different server super global functions to check valid IP address.(http client IP and http x forwarded for, remote address)
$http_x_forwarded_for = $_SERVER[‘HTTP_X_FORWARDED_FOR’]; //checking for proxy server
$remote_addr = $_SERVER[‘REMOTE_ADDR’]; //
$ip = $http_client_ip;
$ip = $http_x_forwarded_for;
$ip = $remote_addr;
$_SERVER[‘HTTP_CLIENT_IP’] : This function will be used to get ip address of internet not the local ip address or ip address which is assigned by router.
$_SERVER[‘HTTP_X_FORWARDED_FOR’] : This function will be used to find client computer is using proxy server or not.
$_SERVER[‘REMOTE_ADDR’] : This is the remote ip address of the computer.
I hop this article helped you to find ip address in php, if you have any problem while using this code just let me know by using comment form.