ANIL KUMAR PANIGRAHI 's Blog

How to get the real IP address using php?

Posted by: Anil Kumar Panigrahi in: ● October 15, 2009

The code will get the real IP address of running those scripts.

<?php

function getRealIpAddress()

{

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;

}

echo getRealIpAddress(); // display the real IP address

?>

it will be useful.

Demo is at http://labs.anil2u.info/realIP.php

Share on Twitter

3 Comments to "How to get the real IP address using php?"

1 | Webby Scripts How to get the real IP address using php?

15 de October de 2009 to ● 1:58 pm

[...] more here: How to get the real IP address using php? [...]

3 | Sumeet

17 de June de 2010 to ● 12:54 pm

Its really useful

Write Comment

About Me

  Anil Kumar Panigrahi
  Software Engineer (PHP)
  Blogger & Founder of Anil Labs
  Baruva, India

You can share with me . . .

My Own Contributions

1) First contribution for codeigniter framework ( multi language support using google translate API ). we can get files from http://github.com/nyros/codeigniter_multilanguage


2) Audio and Video Streaming using FFMpeg and PHP -complete doc file : http://www.docstoc.com/docs/8300349/Audio-and-Video-Streaming

Twitter Updates

Follow me @anil2u
  • http://www.google.co.uk/ logo is changing with mouse move . . . - posted on 07/09/2010 10:57:33
  • True enemies are real friends . . . - posted on 06/09/2010 10:15:29
  • Just watched nice movie " Madrasapattinam ". - posted on 05/09/2010 16:20:48
  • We will always be thankful to our teacher for all the hard work and efforts they have put in, for educating us.- Happy teachers Day . . . :) - posted on 05/09/2010 05:39:13
  • Working on shipping cost functionality (UPS and USPS) for oscommerce shopping cart - posted on 01/09/2010 09:40:03