[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Redirect ie4/net40 and the rest

Posted on 1998-10-31
3
Medium Priority
?
143 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 150 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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

650 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