Solved

Redirect ie4/net40 and the rest

Posted on 1998-10-31
3
132 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace  text in a file 2 111
.properties file to call function/method 9 61
html form to write data to csv 24 117
Create an automated page index 9 21
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

825 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