Page 1 of 1

Switch page without using headers?

Posted: Sat Feb 05, 2011 2:25 pm
by Domsore
As my headers are already set I can not use the header() function. And for my log out script to work I need to switch page.. Is there anyway to do this?

Cheers

Re: Switch page without using headers?

Posted: Sat Feb 05, 2011 6:29 pm
by MindOverBody
You can use ob_start and ob_end_flush functions in your index page. In this case, page will be buffered first, and then outputted. In between of those two functions you can use header function, and "headers already set" message will not happen.

Example:

Code: Select all

<?php ob_start(); ?>
Hello World !!! 
<?php setcookie("name","value",100); ?>
Again !!!
<?php ob_end_flush(); ?>
Also, you can achieve this by editing php.ini file.
; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit. You can enable output buffering during runtime by calling the output
; buffering functions. You can also enable output buffering for all files by
; setting this directive to On. If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On', as
; a value for this directive (e.g., output_buffering=4096).
output_buffering = On

Re: Switch page without using headers?

Posted: Sun Feb 06, 2011 9:11 am
by Domsore
Perfect, thanks for this.

Dom