Today’s Post is about Getting Visitor’s Real IP Address Using PHP, you can get visitor IP with the help of server Environment Variables in PHP.
we can easily get visitor’s ip address with
$_SERVER[‘REMOTE_ADDR’] is the only reliable IP address you’ll get – it’s extracted directly from the TCP stack and is where the current connection was established from. This means if the user is connecting via a proxy, you’ll get the proxy’s address, not the user’s.
So we can’t trust the result of above variables, So In order to get the real correct ip address we have to use some other server variables.
Note: HTTP_X_FORWARDED_FOR sometimes returns internal or local IP address, which is not usually useful. Also, it would return a comma separated list if it was forwarded from multiple ipaddresses.
$_SERVER is an array contains server variables created by the web server.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.