Gossamer Forum
Home : General : Perl Programming :

$ENV{'REMOTE_ADDR'}

Quote Reply
$ENV{'REMOTE_ADDR'}
Through some research I thought that I had finally learned how to find the remote address of any given usr viewing a site. I tried using the environmental variable REMOTE_ADDR and I even checked to see how other similar scripts used this variable. I would like to have this tell me the remote usuer's ip but all I seem to get are errors. This piece gives me an error "...Can't find string terminator '"' anywhere before EOF..."

print "your ip: ", $ENV{'REMOTE_ADDR'};

Other pieces however do not give me this error. such as this piece:

print "Server Name: ", $ENV{'SERVER_NAME'};

My goal is to be able to identify users from a log file and add new users using their ip. I am really new to this so I don't know much about all the little tricks to make these things work. I would appreciate some ideas on what I am doing wrong or an alternative I can use.
------------------------------------------------------------
......and why not?
Quote Reply
Re: [A1R3S3F7R] $ENV{'REMOTE_ADDR'} In reply to
You are likely to have errors elsewhere in your code causing the problem as both those examples would not cause the error.

Last edited by:

Paul: Nov 25, 2002, 2:54 AM
Quote Reply
Re: [A1R3S3F7R] $ENV{'REMOTE_ADDR'} In reply to
As I found out just recently, you may need to use double quotes...i.e;

$ENV{"REMOTE_ADDR"};

This may not be the case....as Paul said, its more likely a problem with something not being closed off or something,m further up the script.

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] $ENV{'REMOTE_ADDR'} In reply to
You certainly don't have to add double quotes, actually, you can leave them away alltogether as long as your hash keys only contain letters, numbers and underscores.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] $ENV{'REMOTE_ADDR'} In reply to
Mmm, maybe it was just with this code that it needed double quotes;

$q='&'.substr($ENV{'QUERY_STRING'},0,256);

(leaving it as 'QUERY_STRING' just gives 500 IS Errors). Could be because some version of Perl don't like using single quotes in substr()'s Unimpressed

Anyway, thats the logic behind me saying that ;)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] $ENV{'REMOTE_ADDR'} In reply to
It seems rather unlikely that it is perl unless you are using like perl 1.001 Wink

There is no logical reason why it would cause an error.
Quote Reply
Re: [Paul] $ENV{'REMOTE_ADDR'} In reply to
Nope, its Perl 5.01. I only found out there was a problem after having a bug found in one of my scripts on another persons server....it was this that caused the error....Crazy

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] $ENV{'REMOTE_ADDR'} In reply to
5.01?.....I didn't know there was such a version. You should probably upgrade Laugh
Quote Reply
Re: [Paul] $ENV{'REMOTE_ADDR'} In reply to
Like I said, its not my server Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] $ENV{'REMOTE_ADDR'} In reply to
I'm still skeptical that it was that, that caused the error.
Quote Reply
Re: [Paul] $ENV{'REMOTE_ADDR'} In reply to
Erm, why? Thats what I did, and thats what fixed it. I didn't touch any other part of the script....

I know its weird, but thats definatly what happened Laugh

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] $ENV{'REMOTE_ADDR'} In reply to
Quote:
Erm, why?

Because it's not logical. Perl treats single and double quotes identically execpt for variable interpolation so I don't see why changing to double quotes would fix anything.
Quote Reply
Re: [Paul] $ENV{'REMOTE_ADDR'} In reply to
Cool I tried playing with the html a little it and I think it may have been something to do with the the ""'s I got it to work anyway so atleast I know now that is indeed the correct env variable. NEXT STEP: Make it work with a log file Smile Thanks for the help.
------------------------------------------------------------
......and why not?