What is the purpose of using PHP to bypass a proxy server and obtain the original IP address?
When a user accesses a website through a proxy server, the website sees the IP address of the proxy server instead of the user's original IP address. To bypass the proxy server and obtain the original IP address, PHP can be used to access the user's IP address from the $_SERVER superglobal variable.
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
echo "User's original IP address: " . $ip;
Keywords
Related Questions
- What are the potential pitfalls of using fopen to download external files in PHP, and how can they be mitigated?
- What are the potential pitfalls of updating database entries using the UPDATE statement in PHP?
- How can one ensure that a specific URL is always displayed in the browser address bar in PHP?