Click to See Complete Forum and Search --> : cgi, perl, php browser detection
ahinalu
12-10-2002, 01:59 AM
Ok before you say go to the javascript section wait...
I am wondering if there is a way to detect the browser type and version so as to redirect certain browser/version combos to a diferent area/html page. As was pointed out to me in the javascript section, if they have js turned off the js detection will not work, my boss gets angry letters saying our site is 'broken' etc ad nauseum.
So can it work? I really suck at perl took me 3-1/2 hrs just to stop the formail script from sending every 0.00 in my reservation form to the mail and html responses.
Blah blah blah, I digress....so can it?...any takers???
If it makes a dif' I have a good relationship with my ISP
Aloha Chris
jeffmott
12-10-2002, 04:15 AM
You can get browser and os type and version through the HTTP_USER_AGENT environment variable. It could appear as the following
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
You can use the HTTP::Headers::UserAgent module to parse this information.
But this still will not tell you whether the user has JavaScript enabled or not. What you could do is have your index page the non-js version with an embed script to redirect to the js version. If they have js enabled then they'll be redirected to the js page, otherwise they remain on the non-js page.
Charles
12-10-2002, 06:02 AM
If you are using Perl then you might find it easier to use the user_agent() function/method of the ubiquitous CGI.pm module (http://theoryx5.uwinnipeg.ca/CPAN/data/perl/CGI.html#FETCHING_ENVIRONMENT_VARIABLES).
Charles
12-10-2002, 08:45 AM
And furthermore,
Using JavaScript to redirect away from the JavaScript free version doesn't work if somebody links to the JavaScript dependent page. Your client will still get those nasty comments. The solution is to use JavaScript in such a way that your page still 'fails safe'. Back up all of your client side form validation server side. Use <a href="http://www.w3.org" onclick="window.open(this.href)">W3C</a> to open a pop up window. Use server side includes. There's always a way, you just have to be clever about it.
jeffmott
12-10-2002, 11:21 AM
If you are using Perl then you might find it easier to use the user_agent() function/method of the ubiquitous CGI.pm module
This is actually a rather useless area of CGI.pm. Loading a module and calling a method seems rather silly when the same value is already easily accesible through a preloaded variable.
$ENV{HTTP_USER_AGENT}
Likewise [quoteIf you give this method a single argument, it will attempt to pattern match on it, allowing you to do something like $query->user_agent(netscape);[/quote] is also pointless as it replaces only a single statement that must again be loaded and executed from a module.
/netscape/i;