Subscribe to Tutorial Feed

Flash and PHP Bible

The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.

The Flash and PHP Bible has a forum for quick support.

Scriptplayground » tutorials » php » Show Users IP

Show Users IP

Here is a simple tutorial to display the visitors IP. You can also capture the IP and use it in other parts of your code.

$user_ip = $SERVER['REMOTE_ADDR'];
print "Your IP Address is " . $user_ip;

The above lines of code grab the users IP address and display it. That is all there is to grabbing the users IP.

Follow Scriptplayground on Twitter (@scriptplay)

Comments: Show Users IP

 Jesse  Sat Dec 3, 2005 7:46 am  
Thanks, this is usefull :)
 Callum  Wed May 2, 2007 1:41 pm  
This script is avalible everywhere but still its extemely useful. Thanks!
 Joe  Sat Aug 18, 2007 8:47 am  
Where is the IP displayed?
 Colin  Wed Dec 19, 2007 3:39 pm  
print "Your IP Address is " . $user_ip;
Where it says $user_ip that shows them it.
 amir  Wed Mar 4, 2009 4:53 pm  
i want to know the ip for a comment in a site thats not mine
is it possible??
 mkeefe  Wed Mar 4, 2009 7:39 pm  
@amir - Not unless the server publishes it, which is not common.
 Ravi  Thu Apr 29, 2010 1:02 pm  
is it possible to display the ip in a localhost server,coz ths script is not working in my site for localhost
Add a comment
The ability to add new comments has been disabled in this archived version.

Main | Tutorials | Articles