Php: getting visitors' real IP addresses _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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.

...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.