1

Topic: Displaye your real ip

<?php
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
echo 'Your IP is: '.$ip; ?>

What do youse think?

2

Re: Displaye your real ip

Cool...

$_SERVER['HTTP_X_FORWARDED_FOR'] is proxy behind the NAT router. And it could contain multiple IP addresses if the request was forwarded trough multiple proxies. So, maybe convert it to an array, something like this:

 $ip = array();
    // check if it's set, and if it's more then one
    if  (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && strpos($_SERVER['HTTP_X_FORWARDED_FOR'],','))  
    {
        $ip +=  explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);     //add IPs from all proxies to the ip array
    } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) 
    {
        $ip[] = $_SERVER['HTTP_X_FORWARDED_FOR'];                      // add the one that you got
    }
   $ip[] = $_SERVER['REMOTE_ADDR'];                                            // the default one