Switch page without using headers?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Domsore
Forum Commoner
Posts: 46
Joined: Wed Jan 26, 2011 7:07 pm

Switch page without using headers?

Post 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
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: Switch page without using headers?

Post 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
Domsore
Forum Commoner
Posts: 46
Joined: Wed Jan 26, 2011 7:07 pm

Re: Switch page without using headers?

Post by Domsore »

Perfect, thanks for this.

Dom
Post Reply