IP Grabber

This simple script allows you to return the users IP address using getenv variables. Originally posted on 227net and works in PHP4 and up. Note: This will return your internal IP when running through a local server.


<?php
// ip_grabber
/* Note: You can also check against $_SERVER variables not included in this script */
function ipGrabber() {
    if(
getenv("HTTP_CLIENT_IP")) {
        
$ip getenv("HTTP_CLIENT_IP");
    } elseif (
getenv("HTTP_X_FORWARDED_FOR")) {
        
$ip getenv("HTTP_X_FORWARDED_FOR");
    } else {
        
$ip getenv("REMOTE_ADDR");
    }
    return 
$ip;
}    
/* Example usage */
echo "<p>Your IP is: <b>"ipGrabber() ."</b>.</p>";
?>

Syndicate content