Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

ENV variable

by irah (Pilgrim)
on Feb 02, 2009 at 07:51 UTC ( [id://740637]=perlquestion: print w/replies, xml ) Need Help??

irah has asked for the wisdom of the Perl Monks concerning the following question:

I read in article from some other website, to find the browser type, get the key HTTP_USER_AGENT from ENV and he used pattern matching for finding browser type. But in my environment (Debian Linux) I checked there is no key called "HTTP_USER_AGENT". Is there any other way available to find the browser type in Perl?.

Replies are listed 'Best First'.
Re: ENV variable
by Corion (Patriarch) on Feb 02, 2009 at 07:54 UTC

    $ENV{HTTP_USER_AGENT} is only set by your webserver when it runs your script (as a CGI script). It is not set in your shell, because there is no browser connected to your shell session. How did you check the contents of %ENV, and in what environment?

      My program follows, sub is_firefox { my $agent = ''; $agent = $ENV{"HTTP_USER_AGENT"} || ''; if (length($agent) && $agent =~ m/firefox/si) { return 1; } return 0; } I have printed all the keys and values of %ENV using while and each. I have checked this in Debian Linux, and Apache server.

        It's quite possible that your browser does not send its user agent.

        Also, what code you've shown is not a complete program, hence I cannot tell whether there is some other error. You should consider starting using CGI or CGI::Mini, which have the ->user_agent() method, which caters for other ways of passing the user agent around. For example, mod_perl likely doesn't set $ENV{HTTP_USER_AGENT}, because %ENV is process global and mod_perl can run in system threads.

Re: ENV variable
by fmerges (Chaplain) on Feb 02, 2009 at 09:11 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://740637]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2025-11-07 22:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (65 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.