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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IP Probelm

Status
Not open for further replies.

Al3inguy

Programmer
Nov 15, 2002
8
AE
hi all

i have a script and it shows the user ip i used this code on it

@gettheip = split(/\./,$ENV{'REMOTE_ADDR'});

but as i know this will get the proxy ip not the real ip for the user. then i changed to this one

@gettheip = split(/\./,$ENV{'HTTP_X_FORWARDED_FOR'});


and sometimes will get the ip and some time no ip show ... so is there any way to make this code work if it can't get the REMOTE_ADDR it will get the HTTP_X_FORWARDED_FOR and vice versa .....
 
Code:
@gettheip = split(/\./,$ENV{'REMOTE_ADDR'}) if exists $ENV{'REMOTE_ADDR'};
@gettheip = split(/\./,$ENV{'HTTP_X_FORWARDED_FOR'}) if exists $ENV{'HTTP_X_FORWARDED_FOR'} unless exists $ENV{'REMOTE_ADDR'};
or
Code:
if (exists $ENV{'REMOTE_ADDR'}) {@gettheip = split(/\./,$ENV{'REMOTE_ADDR'});}
else {@gettheip = split(/\./,$ENV{'HTTP_X_FORWARDED_FOR'})}
BTW, you can never be certain that the IP is in fact the IP of the end-user and not some proxy in between. Not all proxies supply the forwarded-for information, and even if they do, it may represent another proxy.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Change
[tt]else {@gettheip = split(/\./,$ENV{'http_X_FORWARDED_FOR'})} [/tt]
to read
[tt]else {@gettheip = split(/\./,$ENV{'http_X_FORWARDED_FOR'});} [/tt] //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top