I am facing an issue with $_SERVER[‘REMOTE_ADDR’] in PHP
It is giving a IPv6 like value even though the server is using IPv4.
Can anyone help me to resolve this issue.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The server is then accepting connections on an IPv6 socket. Some operating systems can do both IPv4 and IPv6 on an IPv6 socket. When that happens the IPv6 address will look like
::ffff:192.0.2.123or::ffff:c000:027bwhich is the same address but written in hexadecimal.If you see IPv6 addresses like
2a00:8640:1::224:36ff:feef:1d89then your webserver really is reachable over IPv6 🙂Anyway, to convert everything back to a canonical form you can use something like:
Using this code, when you input one of the following:
you always get the canonical IPv4 address
192.0.2.123as output.And of course IPv6 addresses get returned as canonical IPv6 addresses:
2a00:8640:0001:0000:0224:36ff:feef:1d89becomes2a00:8640:1::224:36ff:feef:1d89etc.