You can do that with a javascript command:

if($dbfail) {
<script language=javascript>
exit;  // Halt the rest of the page from loading

"Dan Tappin" <[EMAIL PROTECTED]> a écrit dans le message de news:
> I am trying to add error trapping to my site.  In particular I want to
> direct visitors to an error page when for what ever reason a MySQL
> connection can not be made.  Rather than a page full of errors I want a
> generic 'we are temporarily closed performing maintenance etc.. etc'
> Basically after a failed mysql_connect attempt I want a redirection to
> error page.  I have searched the PHP site and mailing lists and I have
> a few solutions.
> In particular I found the use of ob_start() before the header info is send
> on the page then the use of the follow for the redirect:
> if($dbfail) {
> ob_end_clean();
> header("Location: http://".$SERVER_NAME."/closed.php";);
> exit;  // Halt the rest of the page from loading
> };
> I have also thought about just using a mysql_connect test in the header of
> each page that I have a mysql query in and have the redirect there.  I
> to have such an include any way to add some generic functions to call from
> anywhere as well.
> My only concern is that I am adding another mysql_connect and I don't want
> to slow things down any (things are blazing fast now but I want to keep it
> that way).
> It would be really nice if there was a one line function that could do
> I also use Lasso and they have a simple [URL_Redirect:'']
> tag which does the job.
> I am also unfamiliar with the output buffer functions even after reading
> on them in the manual.  If I call ob_start() at the start of my page do I
> need to call a closing ob function after my $dbfail code if the connection
> is successful and my redirect ob_end_clean(); call is not made?
> Any help would be greatly appreciated.
> Thanks,
> Dan
> P.S. Please CC me/the list as I am on Digest Mode :^)
> --
> Dan Tappin
> Wavefront Communications Limited
> P:(403) 241-0062
> F:(403) 241-0302

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to