After Google finds this code, you can obtain the IP address based on your environment. if you need the IP address, you can refer to the code, but I always wanted to use the ipv6-test API 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, 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;
}
?>