Possible Duplicate:
Headers already sent by PHP
I have a class file that handles registrations and after a successful registration I want to redirect them to another page, but if I use something like:
if(!isset($_SESSION['referer'])) {
$_SESSION['referer'] = "home.php";
header("Location: " . $_SESSION['referer']);
exit();
}
I get the error:
Warning: Cannot modify header information - headers already sent by ...
Is there an alternative (non java script) way of redirecting the user to another page?
Here is my current code flow:
// index.php file
<?php
include('header.php');
include_once('classes/class.signup.php');
$signUp = new SignUp();
// redirect in signup.php class
if(!isset($_SESSION['referer'])) {
$_SESSION['referer'] = "home.php";
header("Location: " . $_SESSION['referer']);
exit();
}
You can try with html meta tag. First value is delay in seconds, second the url you want to redirct to.
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">
You most likely get this error because somewhere before you call the header() function you output something to the browser, by an echo for example. You can use the a combo of ob_start() and ob_end_flush() as a quick fix, but perhaps you should reconsider the flow of your application. For the ob (output buffer) functions look here: http://www.php.net/manual/en/function.ob-start.php.
Edit: even a space or other whitespace before php opening or closing can cause the same effect.
Edit2: Can't really see if anything's wrong with your code in your example. Try the output buffer functions and see if helps. Don't want to use them? Than you'll have to track down the output you already sent.
You can use your web-browser's 'view source' function to investigate whether there are stray characters written to the output of the page before the exception. Perhaps one of your included files is the culprit.