Hi guys today will point out on how to use real user IP , incase you want to use it do a lot of things on your website.
Using the below code to find a client IP address is very bad.
$_SERVER['REMOTE_ADDR']
I have fallen a victim the time i used it to do a lot of things like, using Client IP for tracking pageviews, blacklisting and voting, but at the end it didn't work as i excpeted .
What $_SERVER['REMOTE_ADDR'] does is to collect the real IP of your hosting instead of an IP per a user.
I could remembered the time i used it before i switched on using cookies, which works very well, but now have found a best way you can get real user IP.
This is the only method for now that works, and don't try it when working offline , always do it on live server
How to get real user IP
i recommended using below code to get your real user IP
What HTTP_CF_CONNECTING_IP does is to collect the real ip of a user that is making a request to the server.
See working example here : Click to view it
You can change your IP using IP changer when testing it and also test for
You will see that your IP will be the same when using this method.
If this article help , kindly share it and drop a question on the comment box.
Happy coding
Be first to comment