Page 1 of 1

IP lookup or HTTP referer

Posted: Wed Aug 06, 2003 11:15 pm
by theclay7
I want to know if there is a function that I can know the IP of a user.

For HTTP_REFERER, I can get the URL from the user such as http://www.sony.com.

BUT is there any way I can also know the IP of that?

thanks.

Posted: Thu Aug 07, 2003 10:44 am
by m3rajk
not in the $_SERVER array that i know of. try doinf a dns look up on it

Posted: Thu Aug 07, 2003 11:35 am
by patrikG
Have a look at gethostbyname() in the manual.

Posted: Thu Aug 07, 2003 7:29 pm
by dataangel

Code: Select all

$ip = getenv ("REMOTE_ADDR"); // get the ip number of the user

Posted: Thu Aug 07, 2003 7:50 pm
by Kriek
Cross-version function for retrieving the IP address w/ hostname cleanup ;)

Code: Select all

<?php
    /*
    kriek at jonkriek dot com
    */
    function getIP() {
        if (isset($_SERVER)) {
            if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                return $_SERVER['HTTP_X_FORWARDED_FOR'];
            } else {
                return $_SERVER['REMOTE_ADDR'];
            }
        } else {
            if (isset($GLOBALS['HTTP_SERVER_VARS']['HTTP_X_FORWARDER_FOR'])) {
                return $GLOBALS['HTTP_SERVER_VARS']['HTTP_X_FORWARDED_FOR'];
            } else {
                return $GLOBALS['HTTP_SERVER_VARS']['REMOTE_ADDR'];
            }
        }
    }
    $user = getIP();
    $fullhost = gethostbyaddr($user);
    $host = preg_replace("/^[^.]+\./", "*.", $fullhost);
?>

Your IP address is <?=$user?> | Your host is <?=$host?>
Your IP address is 24.26.91.100 | Your host is *.tampabay.rr.com