Click to See Complete Forum and Search --> : Redirect a browser to another page


SyllasR
09-11-2003, 03:23 PM
Hello all,

In our public web site there is a web page that contains a link to a dedicaded web site like the following:
HTTPS://OurCompanyWebSite.ca/AuthenticatedClients.asp.
All our clients access the dedicaded server from the public web site using this link.
Everything works fine.
But the perlscript I want should be able to redirect our clients to another page when the dedicaded server is down. I would like this script to be compatible to the most popular browsers
( I don't know perl. I've just started learning it . They told me perl could do it )

Thanks in Advance !

Syllas

jimr451
09-15-2003, 02:44 PM
Syllas,

If you'd like the script to figure this out "on the fly" - meaning, dynamically determine when the primary site is down, and swap to the secondary, then the perl script will have to poll the dedicated site.

There are several perl modules that let you load a web page. You're script would basically have to do this, to ensure the site is up, then pass the redirect code to the user. If the site is down, send the user to the alternate.

Note, this method will slow down the response, since the script must do this extra networking.

You could also have another script run in the background and just poll the dedicated box every minute or so - perhaps update a file or something. Then the redirecting script could just check that file and know where to send the user.

I know this isn't a straightforward answer, but I'm not sure there is one. Perl can definitely do what you want, but it will require some coding. Maybe this gets you pointed in the right direction.

-Jim

SyllasR
09-16-2003, 11:44 AM
Jim,
I prefer that the script starts running at the time they click the link related to the dedicaded server

Thank you for your help

Syllas

Scriptage
09-16-2003, 05:54 PM
This will do what you want unless your server doesn't have the CGI and LWP modules installed:

#!/usr/bin/perl -w

use CGI qw(:all);
use LWP::Simple qw(get);
use strict;

my $page = "HTTPS://OurCompanyWebSite.ca/AuthenticatedClients.asp";

$page = "errorpage.html" unless get($page);

print redirect(-uri => $page);

simpson97
09-16-2003, 06:28 PM
Syllas,
This will also doit if your server runs PHP & cURL

<?php

$primary_Site = "http://www.primarydomain.com/????.html";
$secondary_Site = "http://www.secondarydomain.com/????.html";

$ch = curl_init(); // init cURL session
curl_setopt($ch, CURLOPT_URL, $primary_Site); // set URL to primary site
curl_setopt($ch, CURLOPT_HEADER, true); // set HEADER
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // set don't echo to STDOUT
curl_setopt($ch, CURLOPT_RANGE, '1-2'); // return 2 bytes after header
//curl_setopt($ch, CURLOPT_TIMEOUT, 6); // set # of seconds to wait
$return_string = curl_exec($ch); // get HEADER from primary site
curl_close($ch);

// Redirect depending on what is returned from primary site

if(ereg("HTTP/1.1 206", $return_string)) {
echo "<br>$primary_Site";
redirect ($primary_Site);
} else {
redirect ($secondary_Site);
}

function redirect ($selected_Site) {
print "<html>\n<head>\n";
print "<meta http-equiv='refresh' content='1; url=$selected_Site'>";
print "</head>\n<body>\n</body>\n</html>";
}

exit;

?>

Bob

SyllasR
09-30-2003, 11:13 AM
Hi all,

Thank you



Syllas

SyllasR
11-27-2003, 03:06 PM
Hi Scriptage and All,
I've tried your script on a unix server where perl 5.x is running. I've got no reply from the server when I try to run the script.
The web hosting company told me that the LWP module is installed and I have execute permission

Do you or anybody else have any idea of what could be the problem?

Thank you

Syllas

Scriptage
11-27-2003, 04:50 PM
What do you mean by "no reply form the server"?

I've just checked the program with Yahoo! and it is running fine.

Try changing the file permissions (CHMOD) on the program to 0755.

If this doesn't solve the problem please post your error log.

Regards

Carl