Re: [PHP] Sending a header redirect mid-page

2002-03-28 Thread Dan Tappin

>> -Original Message-
>> From: Dan Tappin [mailto:[EMAIL PROTECTED]]
>> Sent: Thursday, March 28, 2002 12:36 PM
>> 
>> My only concern is that I am adding another mysql_connect and
> 
> Why do it twice?  The connection will still be there later in the script.

Yes... I realized that after I hit send :^)

>> I don't want to slow things down any (things are blazing fast now but I
>> want to keep it that way).
> 
> It's not worth worrying about microseconds

That's what I figured.
 
>> It would be really nice if there was a one line function that
>> could do this. I also use Lasso and they have a simple
>> [URL_Redirect:'http://domain.com'] tag which does the job.
> 
> You could write a function that does that like:
> function connect_to_db($host,$dbName,$user,$pass,$redirectTo) {
> $db = mysql_connect($host,$user,$pass);
> if (!db) {
> log(mysql_error());
> header("Location: $redirectTo");
> exit;
> }
> if (!mysql_select_db($dbname,$db)) {
>  log(mysql_error());
>  header("Location: $redirectTo");
>  exit;
> }
> return $db;
> }

That is a really good idea.  Now do I need to do something like this:



Blaa blaa blaa



>> 
>> I am also unfamiliar with the output buffer functions even
>> after reading up 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? 
> 
> No, ob_end* ends the buffering.

I still do not get the ob stuff.  Is there any issue with having a
ob_start(); in my initial include and no ob_end* after this.  I guess I
still really don't understand what is actual happening when I call
ob_start().  All I know if that I can then call the header function where
ever I want later.
 
I just want to know if I am creating any type security, or memory issue by
calling ob_start and then not calling ob_end*.  I am going to take a guess
that when the server hits the end of the file the end is called anyway.

Thanks,

Dan


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Sending a header redirect mid-page

2002-03-28 Thread Dan Tappin

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 this
error page.  I have searched the PHP site and mailing lists and I have seen
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 want
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 this.
I also use Lasso and they have a simple [URL_Redirect:'http://domain.com']
tag which does the job.

I am also unfamiliar with the output buffer functions even after reading up
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
E: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php