browser detecter

The geek forum. PHP, Perl, HTML, hardware questions etc.. it's all in here. Got a techie question? We'll sort you out. Ask your questions or post a link to your own site here!

browser detecter

Postby Mr. Rogers » Mon Jan 19, 2004 4:58 am

For my site, I have 2 versions of it; one for internet explorer and one for mozilla/netscape, because each one renders frames differently. i was wondering if there is a java script or something i could put on my index page that would detect what browser the person is using and automaticly take them to the right page when they click the enter button?
User avatar
Mr. Rogers
 
Posts: 1512
Joined: Sat Sep 06, 2003 10:23 pm
Location: Chicago, IL

Postby LorentzForce » Mon Jan 19, 2004 5:13 am

i wouldn't use javascript, cos which if i think correctly would make the site go elsewhere, which in mozilla's eyes would make it a site that'd be blocked. you're much better off with php in this opinion, because then you can use the meta that changes pages without mozilla hating it.

regardless, look for environment variables. they are provide lots of info about the client who visits your site e.g. IP address, reference page, and their browser.
Image
User avatar
LorentzForce
 
Posts: 1263
Joined: Sun Jun 01, 2003 3:18 am
Location: Between B and E

Postby shooraijin » Mon Jan 19, 2004 11:21 am

I agree with Lorentz; a CGI would be cleaner and work for many more browsers. Something like:

Code: Select all
#!/usr/bin/perl

if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/) {
   print "Location: http://your.site.com/msie.version.html\r\n\r\n";
} elsif ($ENV{'HTTP_USER_AGENT'} =~ /^Mozilla/) {
   print "Location: http://your.site.com/mozilla.version.html\r\n\r\n";
} else {
   print "Location: http://your.site.com/some.other.browser.html\r\n\r\n";
}



Naturally, add an HTTP response code header if this is NPH or running under altered CGI environments like HTTPi.
"you're a doctor.... and 27 years.... so...doctor + 27 years = HATORI SOHMA" - RoyalWing, when I was 27
"Al hail the forum editting Shooby! His vibes are law!" - Osaka-chan

I could still be champ, but I'd feel bad taking it away from one of the younger guys. - George Foreman
User avatar
shooraijin
 
Posts: 9927
Joined: Thu Jun 26, 2003 12:00 pm
Location: Southern California


Return to Computing and Links

Who is online

Users browsing this forum: No registered users and 87 guests