Simple PHP script to display user’s IP address

< ?php
// Stolen from: http://www.cyberciti.biz/faq/php-howto-read-ip-address-of-remote-computerbrowser/
// and http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html
// with CSS from http://www.w3schools.com/css/css_examples.asp

function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

$adresseip = getRealIpAddr();
?>

Adresse IP: < ?php echo $adresseip; ?>



logo CSDCCS

Votre adresse IP:
< ?php echo $adresseip;?>

3 Comments

  1. Google Chrome 14.0.835.202 Google Chrome 14.0.835.202 GNU/Linux GNU/Linux
    Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1

    Thanks!

  2. Google Chrome 33.0.1750.154 Google Chrome 33.0.1750.154 Windows 8.1 x64 Edition Windows 8.1 x64 Edition
    Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
  3. Rizwan Ahmad

    2014-09-15 at 12:26

    Firefox 33.0 Firefox 33.0 Windows 8.1 x64 Edition Windows 8.1 x64 Edition
    Mozilla/5.0 (Windows NT 6.3; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0

    Its shows remote gateway address but not Local IP Address.

Leave a Reply to Simple PHP ScriptsCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.