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.

<?php
$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 2:46 am  
Thanks, this is usefull :)
 Callum  Wed May 2, 2007 9:41 am  
This script is avalible everywhere but still its extemely useful. Thanks!
 Joe  Sat Aug 18, 2007 4:47 am  
Where is the IP displayed?
 Colin  Wed Dec 19, 2007 10:39 am  
@Joe:
print "Your IP Address is " . $user_ip;
Where it says $user_ip that shows them it.
 amir  Wed Mar 4, 2009 11:53 am  
i want to know the ip for a comment in a site thats not mine
is it possible??
 mkeefe  Wed Mar 4, 2009 2:39 pm  
@amir - Not unless the server publishes it, which is not common.
 Ravi  Thu Apr 29, 2010 9:02 am  
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.

Loading
Main | Tutorials | Articles