Solved

Redirect ie4/net40 and the rest

Posted on 1998-10-31
3
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
Six Sigma Control Plans

695 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