Php obtains the user's IPv4 or IPv6 address code. In fact, this is very simple, but I have always wanted to use the ipv6-test API to get a user IP address ...... But what JSON gets is the IP address of the local server. Forget it, don't study, in fact this is very simple, but I always want to use the ipv6-test API to do a get user IP address ...... But what JSON gets is the IP address of the local server. Forget it, don't study it, and the widgets provided by others are also quite useful. Google finds this code and obtains the IP address based on the user's environment.
For example, when IPv6 accesses www.shiwo.de, the user's IPv6 address is obtained.
P.s. The premise is that the website performs A and AAAA resolution.
The code is as follows:
Function getIP ()/* get client IP */
{
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;
}
?>
The ipv6-test's API is something to get the user's IP address ...... But what JSON gets is the IP address of the local server. Forget it, don't study it ,...