Connect with us

How to get real Client IP address in php (stop using $_SERVER['REMOTE_ADDR'] )

kizinho

Published

on

Follow
How to get real Client IP address in php (stop using $_SERVER['REMOTE_ADDR'] )
Photo: Naijacrawl

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 



kizinho
 Follow

I am a software developer, like meeting people and love blogging, that's why I developed naijacrawl because that's what I love doing.

Continue Reading
Click To Comment

BE First To Comment


    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Latest



    Face of Naijacrawl


    ChukwubuikemSunday ChukwubuikemSunday

    Sunday Chukwubuikem


    Higher - 09061773292

    Trending