Solved

Redirect ie4/net40 and the rest

Posted on 1998-10-31
3
133 Views
Last Modified: 2010-03-04
Hello,

I need a perl script that redirects:

When I use net40 or higher.
When I use ie40 or higher.
When I use an other then above.

I tryed the following script. It works fine but it won't detect ie40 or higher and will redirect instead of that to the netscape site. Is this because netscape and IE40 use both the mozilla description. How do I solve this problem.

#!/usr/local/bin/perl5/

$base_html_page = "http://www.dracotools.com/test/testrest.html";
$net40_html_page = "http://www.dracotools.com/test/testnet.html";
$ie40_html_page = "http://www.dracotools.com/test/testie.html";

##############################################################
# Nothing below this line needs changing - but, feel free.....
##############################################################

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@user_agent =  split(/\//,$ENV{'HTTP_USER_AGENT'});
@version = split(/ /, $user_agent[1]);
$version_number = substr($version[0], 0, 3);

# Microsoft redirection subroutine
if ($user_agent[0] eq "Microsoft"){
    if ($version_number < 4.0) {    #### this is the version use X.X if you change it
      print "Location: $base_html_page\n\n";
    }
    else {
      print "Location: $ie40_html_page\n\n";
    }
}

# Netscape redirection subroutine
elsif ($user_agent[0] eq "Mozilla"){
    if ($version_number < 4.0) {    #### this is the version use X.X if you change it
      print "Location: $base_html_page\n\n";
    }
    else {
      print "Location: $net40_html_page\n\n";
    }
}

# All other Browsers are redirected here
else {
    print "Location: $base_html_page\n\n";
}

greeting Michel Weegerink
mmcw@worldonline.nl
0
Comment
Question by:mmcw
  • 2
3 Comments
 
LVL 5

Expert Comment

by:Christian_Wenz
ID: 1205839
afaik IE has a "compatible" in the HTTP_USER_AGENT. Could that be?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1205840
Could you show what you're getting in HTTP_USER_AGENT in each case?
0
 
LVL 5

Accepted Solution

by:
Christian_Wenz earned 50 total points
ID: 1205841
at

http://www2.nerv.ne.jp/~mina/userlog2/agent.cgi

(and on many other places) you can find a list of http_user_agents. One example for a MSIE4 is this:

Mozilla/4.0 (compatible; MSIE 4.01; MSIECrawler; Windows 95)

so: change:

if ($user_agent[0] eq "Microsoft"){

to
  if ($ENV{'HTTP_USER_AGENT'} =~ /compatible/) {

and your script should work.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question