Trying to determine IP provided by ISP

Hi Friends,

Does anybody have a PHP script which can return the external IP provided by the ISP?  The purpose is rather convoluted, however I'am trying to manage these dynamically allocated IP's.

My Web server is located behind a router or a proxy.

How do I get this IP when called within the Local network?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

//Get users IP Address
$ipaddress = ($HTTP_SERVER_VARS["REMOTE_ADDR"]);
yeah he is right....



I would recommend the new way since the old way will be deprecated...

In order to obtain the IP address from behind a firewall you need to run a PHP script on a webserver outside the router.

So, for example:

place a php file on a cheap webserver (or a friend's) that checks the IP address of the visitor -- using the methods listed above, then have it return the IP address from a function on that page.

Here is some sample source code:


// Pass the hash and the auth to ensure nobody else can access this. change to whatever you want.
if ($hash == "security" && $auth="function"){
     $newip = $REMOTE_ADDR;
     $fp = fopen ("currentip.txt", "wb+");
     fputs($fp, $REMOTE_ADDR);
     fclose ($fp);
     echo 'status='.$REMOTE_ADDR;
} else {
echo 'status=FAILED. ACCESS DENIED';


$fp = fopen("currentip.txt", "r");
$contents = fread ($fp, filesize ("currentip.txt"));

$fp = @fopen("http://".$contents."/index.php","r");
if ($fp)
{ print"sitestatus=online"; }
{ print"sitestatus=offline"; }


Now all you need to do is make a file that loads the data from the currentip.txt, and redirects to: http://".$contents."/index.php

Hopefully that helps out your problem.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ArnnieAuthor Commented:
Thanks for the advice.

The solution you've mentioned is what I suspected.  I just wanted to avoid third party webservers for redundancy purposes.

Thanks again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.