?
Solved

Trying to determine IP provided by ISP

Posted on 2003-02-19
5
Medium Priority
?
219 Views
Last Modified: 2013-12-13
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?

Thanks
Arnnie
0
Comment
Question by:Arnnie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:AhmadKhatib
ID: 7985674
<?
//Get users IP Address
$ipaddress = ($HTTP_SERVER_VARS["REMOTE_ADDR"]);
?>
0
 
LVL 6

Expert Comment

by:carchitect
ID: 7986135
yeah he is right....

$ip=getenv("REMOTE_ADDR");

regards


0
 
LVL 7

Expert Comment

by:Big_Red_Dog
ID: 7987083
I would recommend the new way since the old way will be deprecated...

$ipaddr=$_SERVER['REMOTE_ADDR'];
0
 

Accepted Solution

by:
birdgenj earned 225 total points
ID: 8061652
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:

setip.php
<?php

// 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';
}

status.php
<?php

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

$fp = @fopen("http://".$contents."/index.php","r");
if ($fp)
{ print"sitestatus=online"; }
else
{ 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.
0
 

Author Comment

by:Arnnie
ID: 8070300
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.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question