Solved

Redirect ie4/net40 and the rest

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now