Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Original IP address through PHP headers

Status
Not open for further replies.

insania

Technical User
Feb 11, 2004
53
IE
Hi

I want to be able to read a computers IP address even when it has gone through a router. I have an external website and want to know specifically which PC's on a network have accessed pages. I heard you could do this with headers but the headers dont seem to pick this information up.

I am using this code to read the headers:

$headers = array();
foreach($_SERVER as $k => $v)
{
if(substr($k, 0, 5) == "HTTP_")
{
$k = str_replace("_", " ", substr($k, 5));
$k = str_replace(" ", "-", ucwords(strtolower($k)));
$headers[$k] = $v;
}
}
print_r($headers);

Any help is appreciated
 
You never see the computer's address, so nothing in PHP will work. There's probably a Javascript function that could get this.
 
$_SERVER[REMOTE_ADDR] is the closest you'll get but if theres any NAT translation, all you'll get is the router address.

Java as lgarner says, is probably the way to go.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks guys, I got the external IP address only not the individual computer one with bam720's method.

What would the Java look like for this kind of thing?

Thanks Again
 
The trouble with that is it will in ost cases return the loopback as everything else is deemed routing/NAT, so all you get is 127.0.0.1

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
you're right. behaviour seems to be inconsistent across the various boxes that i have just tested this on. also seems to give loopback on dhcp but not statically assigned addresses.

anyway - i don't think javascript is going to do the trick but java might.
 
Activex would but e
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
KarveR, you have mentioned the "A"-word in the PHP forum. You must now be punished.

Your penance is that you must say 5 "Hail Zend"s, chant 4 "I must write secure code" mantras then while clicking your heels together say three times, "There's no source like open source".



Want the best answers? Ask the best questions! TANSTAAFL!
 
insania:
I go through great lengths to keep my machines' actual IP addresses unknown to the outside world, so why do you want this information so badly?

Anyway, chances are that NATted machines' real IP addresses are all 10.x.x.x, 192.168.x.x or 172.16.x.x unrouteable addresses, which are useless to you as they can be reused in multiple networks.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Its for a clocking in system so the IP address of the computer that a user clocks in with can be stored, but the server is external, hence the needing this tracking thing going
 
are you using IIS? and do your clients use IE? if so you might consider using ntlm authentication and retrieving the machine name rather than the IP address (in the $_ENV super global)

you might be ble to do something similar with apache (check with the guys in the apache forum)
 
Its running on linux (Mandrake) with apache so thanks anyways. Ill try the apache forum aswell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top