Re: redirect

From: Date: Mon, 24 Jul 2000 16:37:32 +0000
Subject: Re: redirect
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-7925@lists.php.net to get a copy of this message
> Is there a way to redirect to a url after code or whitespace? I know > that > the header function doesn't work for this. It can not have anything > printed to the screen prior > to it. > So how can you redirect from a place deep in the code? There are a few ways to do this. First a very primitive (and not very elegant) solution: Replace all your echo and/or print statements with a line like this: $buffer .= ”whatever we want to print”; If you pass through all the script without redirecting, then you output the buffer like this: echo $buffer; you could also use an array like $buffer[] = ”line we want to output”;' and then itterate through the array at the end of the script and echo every line. Another way to do it is to enable output buffering (only in PHP 4) in php.ini output_buffering = On ; That will enable output buffering for all files, and will alow you to send header information even after output has started (to overrule the default output buffering you can call the flush() function). You can also enable or disable output buffering at runtime (which is IMHO the best solution) with the output buffering functions (those functions are not currently documented, an overview is below): void ob_start(void); Turn on Output Buffering void ob_end_clean(void); Clean (erase) the output buffer, and turn off output buffering void ob_end_flush(void); Flush (send) the output buffer, and turn off output buffering string ob_get_contents(void); Return the contents of the output buffer void ob_implicit_flush([int flag]); Turn implicit flush on/off and is equivalent to calling flush() after every output call I hope this helps you, Best regards, Jesper Juhl juhl@eisenstein.dk

« previous php.general (#7925) next »