PHP: How to get client IP address

What is the way to get the client's IP address who is browsing your site?

The variable $_SERVER has a field called REMOTE_ADDR, which holds the IP address of your client, means the remote user. Below is the sample code which will print the IP address of the client at your browser.

if( isset($_SERVER['REMOTE_ADDR']) ){
print $_SERVER['REMOTE_ADDR'];
}


Remember, the IP address will be the public one. I ment the IP address that provided by your internet provider. For example 10 people from your area using the service of internet from same provider. And for 10 of them, it will display the same IP address.

Comments

anu said…
From this I know the details about the how to get the client ip using php. Thanks for this information. I normally use ip details to get the ip address lookup