|
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?.
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?
| [reply] [d/l] [select] |
|
|
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.
| [reply] |
|
|
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.
| [reply] [d/l] [select] |
Re: ENV variable
by fmerges (Chaplain) on Feb 02, 2009 at 09:11 UTC
|
| [reply] |
|