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 an IP address $ _ server [& amp; 39; r
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 (! Emptyempty ($ _ server ['http _ client_ip ']) {
- $ Ip = $ _ server ['http _ client_ip '];
- } Elseif (! Emptyempty ($ _ 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.