How php can obtain users' intranet IP addresses from the internet

Source: Internet
Author: User
Whether php can obtain the user's intranet ip address from the internet. if the user connects to the Internet through a router or other devices, php can be used to obtain the intranet ip address of the user, that is, 198. xxx. xxx. ip address like xxx. This refers to access from Internet users, rather than obtaining the intranet where the server host is located! Ip ------ solution ------------ can php obtain the user's intranet ip address from the internet?
Assume that you can use php to obtain the intranet ip address of the user, that is, the ip address 198. xxx. This refers to access from Internet users, rather than obtaining the intranet where the server host is located!

Ip


------ Solution --------------------
You can try a function.


function getIP() {

if (@$_SERVER["HTTP_X_FORWARDED_FOR"])
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if (@$_SERVER["HTTP_CLIENT_IP"])
$ip = $_SERVER["HTTP_CLIENT_IP"];
else if (@$_SERVER["REMOTE_ADDR"])
$ip = $_SERVER["REMOTE_ADDR"];
else if (@getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (@getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if (@getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "Unknown";
return $ip;
}


------ Solution --------------------
Let's take a look at the tcp principle and you will know the reason.
------ Solution --------------------
Generally, this is not acceptable (unless the egress gateway of the intranet is set to "transparent gateway ")

But even if you know it, what does it mean?
You cannot access it from the server!

It's just like some people have to want to know the location of the files uploaded by the user on the user's machine.
Since it is impossible for you to access from outside, what is the purpose of knowing?
------ Solution --------------------
This is not a problem except for hacking the host of the other party.
------ Solution --------------------
Determine that an independent visitor can only use cookies
------ Solution --------------------
Independent visitors are judged by cookies + time.
A cookie is generated to the local device and then p3p is used.
Then calculate a uv every day from.

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.