Saturday, 31 August 2013

Prevent 'headers already sent'

Prevent 'headers already sent'

When you try to redirect an user with Header:Location to another page when
there is already 'output' on the page, PHP will display the message:
headers already sent.
Is it a good solution to create a function, and call that function
wherever you need it (even at the bottom of the page)?
Thanks!
Example:
function redirectMe($location){
header('Location:'.$location);
}
//HTML
//Redirect user:
redirectMe('http://www.google.com');

No comments:

Post a Comment