phphttp-redirect

PHP header redirect not working


I know this has been covered before but I cannot find an answer to this,

I have always used this;

header("Location: http://www.website.com/");
exit();

This has always worked in my current project and all of a sudden it is not working in any of my browsers

I would like to figure out the problem and fix it instead of using

echo "<script type='text/javascript'>window.top.location='http://website.com/';</script>";

I also have error reporting enabled and it shows no errors

// SET ERROR REPORTING
error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);
ini_set('display_errors', TRUE);

Any ideas why it will not work?


Solution

  • Try:

    <?php ob_start();?> --------->this code also
    
    error_reporting(E_ALL | E_WARNING | E_NOTICE);
    ini_set('display_errors', TRUE);
    
    
    flush();
    header("Location: http://www.website.com/");
    die('should have redirected by now');
    

    See what you get. You shouldn't use ^ (xor) in your error_reporting() call because you're unintentionally asking for all errors EXCEPT notices and warnings.. which is what a 'headers already sent' error is.

    Edit:

    Also try putting flush() right above your header() call.