-2

I want use code php to check client use ipv6 or ipv4 network. But this function only return ipv4 address.

function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } 

Please help me to detect client use ipv6! Thanks!

2
  • 1
    Possible duplicate of How to check if someone connected via IPv6 / IPv4 <- I would recommend looking at "Mukesh Chapagain"'s-answer. Commented Jan 20, 2019 at 15:12
  • There's also loads of other hits on this topic if you simply had googled on your title (which you always should do before posting a question). Commented Jan 20, 2019 at 15:16

1 Answer 1

-1
echo $_SERVER['REMOTE_ADDR']; 

if you get ipv4 than client uses ipv4 else ipv6

Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand.
That's just for getting the IP (which the OP already does better than this example). The question is how to detect if the IP they're getting is an IPv4 or IPv6-address.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.