In PHP, we use $_SERVER superglobals to access different server parameter values. We can also get the remote client IP address by use of this superglobal. But what if the remote client is connected to network at his/her location, and is accessing the site. It means there is a proxy through which he access the internet. To overcome this problem, write the following code in your PHP script to get a client remote IP address:
if (getenv(HTTP_X_FORWARDED_FOR)) {$ipaddress = getenv(HTTP_X_FORWARDED_FOR);
} else {
$ipaddress = getenv(REMOTE_ADDR);
}
?>

No comments:
Post a Comment