Forum Moderators: coopster

Message Too Old, No Replies

Redirect to a Temporary Page

         

wener

2:07 am on Aug 4, 2005 (gmt 0)

10+ Year Member



Sometimes when the database can't be reached, the page only show error message. I want to add a conditional redirect into my code so that if the database can't be reached, the user goes to a temporary page.

Can anyone tell me how to do that? What's the function and where should I put the function? Thank you very much.

dreamcatcher

7:56 am on Aug 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Something like this should do the trick:


$dbuser = '';
$dbpass = '';
$dbhost = '';
$dbname = '';

$connect = mysql_connect($dbhost,$dbuser,$dbpass);

if (!$connect)
{
header("Location: yourpage.php");
exit;

//OR use an include

@include('somepage.php');
exit;
}
else
{
mysql_select_db($dbname, $connect);
}

dc

wener

6:26 pm on Aug 4, 2005 (gmt 0)

10+ Year Member



Thank you.
But when I use "Header()" function. It doesn't work. The error message is:
Cannot modify header information - headers already sent by...

I used this line and it works:
echo "<meta http-equiv=\"refresh\" content=\"0;URL=temp.php\">";
return;

Is there any disadvantage (for example, search engines don't like it?) to use the meta tag to redirect to another page when the database can't be reached?