Php obtains the visitor's real IP address. Php obtains the visitor's real IP address. when it comes to me, we need to obtain the real IP address of the user, such as log records, geographic location, user information, and website data analysis, in fact, getting the real IP address of a visitor in php requires us to get the real IP address of a user, for example, log record, geographic location, user information, website data analysis, etc, in fact, it is easy to get the IP address $ _ SERVER ['remote _ ADDR.
Php Tutorial for Obtaining visitors' real IP addresses
At most times, we need to get the real IP address of the user, for example, log record, geographic location, user information, website data analysis, etc, in fact, it is easy to get the IP address $ _ server ['remote _ addr.
*/
// The simplest method
$ Ip = $ _ server ['remote _ addr '];
// As long as the proxy is used, you will not be able to obtain the real IP address. the more detailed method is as follows:
Echo "remote addr:". $ _ server ['remote _ addr ']."
";
Echo "x forward:". $ _ server ['http _ x_forwarded_for ']."
";
Echo "clien ip:". $ _ server ['http _ client_ip ']."
";
// Check an instance.
Function getip (){
$ Ip = $ _ server ['remote _ addr '];
If (! Empty ($ _ server ['http _ client_ip ']) {
$ Ip = $ _ server ['http _ client_ip '];
} Elseif (! Empty ($ _ server ['http _ x_forwarded_for ']) {
$ Ip = $ _ server ['http _ x_forwarded_for '];
}
Return $ ip;
}
/*
If the proxy is encrypted, the real IP address cannot be obtained.
...