PHP _php Tutorial to get the user IPv4 or IPV6 address code

Source: Internet
Author: User
In fact, this is very simple, but I have always wanted to use the Ipv6-test API to do something to get the user's IP address ... Helpless JSON gets only the IP of the native server. Forget, do not study, let alone others provide the widget also very good. Google a bit, find this code, can be based on the user environment to obtain an IP address.

For example, IPV6 access www.shiwo.de gets the IPV6 address of the user

P.S premise is that the site did a and AAAA parsing

Copy CodeThe 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;
}
?>

http://www.bkjia.com/PHPjc/326295.html www.bkjia.com true http://www.bkjia.com/PHPjc/326295.html techarticle In fact, this is very simple, but I have always wanted to use the Ipv6-test API to do something to get the user's IP address ... Helpless JSON gets only the IP of the native server. Forget it, don't study it, ...

  • Related Article

    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.