About Linux FAQ

Browse More FAQs:

PHP Howto Read IP address of remote computer/browser

Posted by Vivek Gite [Last updated: December 10, 2006]

PHP has in built facility to detect remote browser or IP address and other properties. These values are assigned to special variable. In this case, it is assigned to variable called REMOTE_ADDR. You can use any one of the following statement to obtained or read IP address:

$ip = $_SERVER['REMOTE_ADDR'];
OR
$ip= $REMOTE_ADDR;

Here is sample code:

<?
$ip= $REMOTE_ADDR;
echo "<br> Your IP address : " . $ip;
echo "<br> Your hostname : " . GetHostByName($ip);
?>

See PHP getenv for more information.

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Discussion on This FAQ

  1. soroccoheaven Says:

    hi,

    I am trying to figure out the “spam” word enabled form submission like this one …anyone here can help me ..

    Thanks

  2. Dmitri Zhuchkov Says:

    echo “ Your hostname : ” . GetHostByName($ip);

    You can get the host name from IP.gethostbyname

    gethostbyname - Get the IP address corresponding to a given Internet host name

    Try the gethostbyaddr for this task.

  3. Rajesh Says:

    How to get the remote IP location?

  4. Timmehx Says:

    <?php
    $ip = $_SERVER['REMOTE_ADDR'];

    And if you want to echo it use

    that is what i use

  5. Nilesh Says:

    hey! this is a child’s play! such an easy thing! i said that coz i am 15 and a hard core PHP developer!!

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.