Current location: Hot Scripts Forums » Programming Languages » PHP » Redirect based on condition


Redirect based on condition

Reply
  #1 (permalink)  
Old 05-07-04, 05:33 PM
jbilawa jbilawa is offline
New Member
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Redirect based on condition

Good afternoon all,

I need some advise. I am using this script to determine the status of a server:

<?php
//Please change to your server specifications
$live = "http://pathtofile/status/live.gif";
$dead = "http://pathtofile/status/dead.gif";

//The status checking script
//meddle at your own risk!
//check for port number, default is 80
list($addr,$port)= explode (':',"$link");
if (empty($port)){
$port = 80;
}
//Test the server connection
$churl = @fsockopen(server($addr), $port, $errno, $errstr, 4);
if (!$churl){
header("Location: $dead");
}
else {
header("Location: $live");
}
function server($addr){
if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}
return $addr;
}
?>

When the server is online it shows the live.gif and when it is offline it shows the dead gif. Is there a way to optionally redirect to an alternative webpage based on condition? For example, if it is online it would go to online.html or if offline go to offline.html.

Thank you for your assistance.

Jeremy Bilawa
Reply With Quote
  #2 (permalink)  
Old 05-07-04, 05:53 PM
Bonzo's Avatar
Bonzo Bonzo is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 340
Thanks: 0
Thanked 0 Times in 0 Posts
I would think you would have a problem with headers ( as I was ) and I found a post on this forum about using a Meta tag to redirect.

Anthony

PHP Code:

if (!$churl)

{
 echo 
'<meta http-equiv=Refresh content=1;url="online.html ">';
}

else
{
 echo 
'<meta http-equiv=Refresh content=1;url="offline.html ">';

Reply With Quote
  #3 (permalink)  
Old 05-07-04, 06:07 PM
jbilawa jbilawa is offline
New Member
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I am pretty sure I did something wrong. I changed it to the below and no matter if the server is up or down it goes to the first echo variable...

any suggestions?

<?php
//Please change to your server specifications
$live = "http://pathtofile/status/live.gif";
$dead = "http://pathtofile/status/dead.gif";

//The status checking script
//meddle at your own risk!
//check for port number, default is 80
list($addr,$port)= explode (':',"$link");
if (empty($port)){
$port = 80;
}
//Test the server connection
$churl = @fsockopen(server($addr), $port, $errno, $errstr, 4);
if (!$churl){
echo '<meta http-equiv=Refresh content=1;url="http://pathtofile/faq.htm">';
}
else {
echo '<meta http-equiv=Refresh content=1;url="http://pathtofile/contact.htm">';
}
function server($addr){
if(strstr($addr,"/")){$addr = substr($addr, 0, strpos($addr, "/"));}
return $addr;
}
?>
Reply With Quote
  #4 (permalink)  
Old 05-07-04, 06:07 PM
simone's Avatar
simone simone is offline
Newbie Coder
 
Join Date: Nov 2003
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
If what i think you want is this, change
PHP Code:

$live "http://pathtofile/status/live.gif";

$dead "http://pathtofile/status/dead.gif"
to

PHP Code:

$live "http://pathtofile/status/online.html";

$dead "http://pathtofile/status/offline.html"

????

[edit] but uh yeh, i just tested it on my server, went to the offline page.

Oh an also ..did you really need something so complicated?
for example, you could use this...

PHP Code:

<?PHP


$check 
fsockopen ("www.yoursite.com""80");

if (
$check){
echo 
'<meta http-equiv=Refresh content=1;url="online.html ">';
$close fclose($check);
}
else{
echo 
'<meta http-equiv=Refresh content=1;url="offline.html ">';
}

?>

Last edited by simone; 05-07-04 at 06:25 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can they SUE? based on same features, ideas, concept? soccer The Lounge 6 01-20-09 05:28 AM
redirect with php alpine2005 PHP 6 04-09-04 08:45 AM
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
Help! Need to redirect to pages based on posted form data big_t8r ASP 1 12-09-03 05:39 AM


All times are GMT -5. The time now is 10:32 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.