Get Clients IP address using PHP script

3 minutes read

Some times we need the visitor’s IP address for validation, security, spam prevention etc. Getting the Visitor’s IP address is very easy in PHP.
We can get the Internet Protocol (IP) address of any visitor by using PHP.

Get Clients IP address using PHP script

Get Clients IP address using PHP script

The easy way to get the visitor’s IP address in php is :


Some times this does not returns the correct IP address of the visitor. This may happen due to reasons like the user is behind a proxy, your apache server is behind a reverse proxy (e.g. varnish) etc.
So we can use some other server variables to get the ipaddress.

Proxy Server Address
Some visitors browse from behind proxy servers. We can collect the address of proxy along with the IP address of client by using this code.

Other Server variables
$_SERVER is an array and it contains lot of information as supplied by server and one of the element is ‘REMOTE_ADDR’ which gives us the IP address.


Facebook Twitter LinkedIn Telegram Whatsapp

Related Posts:

Now easy Get the lat long coordinates from an address. Type the address which would include the name of the street,city/town, state and country name to get more accurate lat long value. Get Lat Long By Address: //Make Address $address = ...
What is PHP ? PHP stands for Hypertext Preprocessor and is a server-side language. PHP allows web developers to create dynamic content that interacts with databases. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becom...
Calculate sum of html element’s values with specific class names using Jquery. This code is useful in get sum of the elements values of specific class ,id. Jquery Something like the following should work for you: How to get sum of html element's ...