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

$_SERVER in Perl? 3

Status
Not open for further replies.

serpento

Programmer
Jun 16, 2002
92
GB
PHP has a superglobal array called $_SERVER, which is useful when handling 404 errors on Unix Apache servers. In this array you can access REDIRECT_URL, REDIRECT_STATUS, REDIRECT_ERROR_NOTES, and REDIRECT_REQUEST_METHOD variables. Is there a way of accessing these in Perl?

-Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
PERL has a hash called %ENV which contains all the evironmental variables. This will give you a list

print ($_,$ENV{$_}) foreach (keys %ENV);


haunter@battlestrata.com
 
Thanks, but %ENV doesn't seem to have the REDIRECT_ variables I'm looking for. Is it possible to access these in Perl?

-Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
Don't expect people to know PHP. I have absolutely no idea what a REDIRECT_ variable would be good for. From the little information you give I can only deduce that the variable contains a location to redirect. In my opinion this is useless as the programmer decides where to redirect if there's to be a redirection. I would certainly not want a script and/or language that dictates me where to redirect. You'd get better answers if you took the time to explain what "kind" of variable you're looking for, and would also be helpful to know what you plan to do with such a variable.
 
It sounds like you are attempting to search for some state information. PERL state infomation is handled manuelly unlike pHp. Usually, I have a session hash that I create for each person visiting the site. In this hash you can store what ever info you like.

Point me more directly to the problem you are trying to solve and I will solve it for you.


haunter@battlestrata.com
 
Look up CGI::Session on CPAN.ORG for state maintenance

HTH
Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
As Topmach and Haunter suggested, I don't think I went about solving the problem in the right way.

I have a perl script loaded every time there's a 404 error. Can I get to a variable that says what file they were trying to access to get the error?

-Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
Now we are getting somewhere! The HTTP_REFERRER key will tell you where you just came from or the page that just sent you to the current page. More to the point by what method are you calling the PERL script? Through the server or Browser? What is the point of the script?

Let the cat out of the bag so I can help!


haunter@battlestrata.com
 
Just to make it clear, the HTTP_REFERRER key Haunter is refering to is part of the %ENV hash. So $ENV{HTTP_REFERRER} is how you acess it. And is set only when there is a referer. That's why you didn't see it with the code Haunter gave for walking the %ENV hash earlier.
 
I found $ENV{'HTTP_REFERER'} as opposed to the 2R version, Is this a synonym?

Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
That'll teach me for being lazy and copy and pasting from others. $ENV{HTTP_REFERER} it is indeed.
 
Thank you, that $ENV{'HTTP_REFERER'} is all I needed. I'll ask questions more directly in future.

-Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top