Redirection Based on Browser

I have a page on my site where I need one file to be loaded for Internet Explorer users and another page to be loaded for Netscape users.  I have tried this script:

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

if ($ENV{'HTTP_USER_AGENT'} =~ /^Mozilla\/*.*/) {
    print "Location:http://www.absolutcollectors.com/gallery/no.shtml\n\n";
}
else {
    print "Location:http://www.absolutcollectors.com/gallery/yes.shtml\n\n";
}

You can try it out at http://www.absolutcollectors.com/gallery/test.cgi

It is supposed to send netscape users to no.shtml and all other users to yes.shtml, but it sends everyone to no.shtml it seems.  Please help me figure this out.  I am doing this because of a strange problem...when you visit http://www.absolutcollectors.com/gallery in netscape, it prints the code instead of reading the html.  It works fine in Internet Explorer. Why does it do this???

Help with any of these questions would be greatly appreciated!!

Alex
alexswebsiteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alexswebsiteAuthor Commented:
Try visiting http://www.absolutcollectors.com/gallery/yes.shtml in both IE and Netscape to see how it prints the code in netscape and shows the page properly in IE.
0
ozoCommented:
http://members.xoom.com/absolutvodka/header.shtml
returns with a header saying it's
Content-Type: text/plain
so Netscape is doing the right thing.
If you want it to be interpreted as HTML it should return a header saying
Content-Type: text/html
0
alexswebsiteAuthor Commented:
It says

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

I don't see text/plain anywhere, am I looking in the wrong place?

Alex
0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

ozoCommented:
but the http headers sent before that say:
Connection: close
Date: Tue, 04 Jan 2000 05:25:25 GMT
Accept-Ranges: bytes
Server: Apache/1.2.5
Content-Length: 1596
Content-Type: text/plain
ETag: "3e2f72-63c-386c2f4a"
Last-Modified: Fri, 31 Dec 1999 04:21:30 GMT
Client-Date: Tue, 04 Jan 2000 05:28:20 GMT
Client-Peer: 206.132.163.167:80

So everything after that is treated as just what you said it was, 1596 characters of text/plain, and the "<meta http-equiv" is just part of the litteral text

0
alexswebsiteAuthor Commented:
There is no way for me to change that, because the server is on Xoom, and I can't change the settings.  (is it that netscape does it right and IE does it wrong, but it shows up)  Do you know how I can make my cgi script work?

Thanks,
Alex
0
guadalupeCommented:
Mozilla comes back in all User agents try changing the test to

if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/)
{
#MS
}

else {#Netscape}
0
alexswebsiteAuthor Commented:
I have changed the file (http://www.absolutcollectors.com/gallery/test.cgi) to the following based on your advice:

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/)
{
    print "Location:http://www.absolutcollectors.com/gallery/yes.shtml\n\n";
}
else {
    print "Location:http://www.absolutcollectors.com/gallery/no.shtml\n\n";
}

It still sends both IE and Netscape to the no.shtml file.  Please let me know if this is because I have implimented your suggestions incorrectly.  Thanks for your help...if it works later, I'll accept your answer.

Alex


0
guadalupeCommented:
I tried it and it worked fine.  Try putting only this in a cgi file and running it and see where it send you:


if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/)
{
    print "Location:http://www.absolutcollectors.com/gallery/yes.shtml\n\n";
}
else {
    print "Location:http://www.absolutcollectors.com/gallery/no.shtml\n\n";
}



Thats how I tested it and it went off fine.  I used IE 4.1 & 5.00 and Netscape 3.1 and 4.6.  Remember that now yes.shtml indicates IE.
0
alexswebsiteAuthor Commented:
Thanks!  It works fine....I  got rid of the line

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

which I had before all of what you suggested and that fixed the problem.  Thanks for your help.  Please submit something as an answer and I'll give you the points!

Alex
0
guadalupeCommented:
Mozilla comes back in all User agents try changing the test to

if ($ENV{'HTTP_USER_AGENT'} =~ /MSIE/)
{
#MS
}

else {#Netscape}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alexswebsiteAuthor Commented:
Thanks for your help!
Alex
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.