: This article describes how to obtain the real IP address of a user using PHP. For more information about PHP tutorials, see. I was asked to pass the interview a few days ago.
$_SERVER['SERVER_ADDR']What is the problem with the obtained IP address? It must be "if the user cannot obtain the real IP address through a proxy ". Fortunately, the interviewer did not ask further questions. So how can we get the real IP address of the user?
Analysis
Nowadays, many users do not directly dial the Internet, but access the network through routers or other proxies. If we want to obtain the real IP address of the user client, we cannot directly use$_SERVER['SERVER_ADDR']Because the obtained ip address may be a ** Lan ** ip address such as 192.168.1.99, rather than the user's public ip address.
Fortunately, when our access requests are routed through the public network or the proxy server, the terminal will addX-Forwarded-ForHeader information. we can use this request header to obtain the real IP address of the client.
Code
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes how to obtain the real IP address of a user in PHP, including some content, and hope to help those who are interested in PHP tutorials.