tags:

views:

364

answers:

5

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/';&lt;/script&gt;";

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?

A: 

Try removing the Space Between location and the first h in http.

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

turns into

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

I had this problem on my WAMP Server.

Although it shouldn't be the problem, considering that is how it is documented in the PHP documentation. But you should probably try it anyway. I know it has worked for me in a number of cases.

Chacha102
+4  A: 

Try:

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.

Mike B
My money is on 'headers already sent'.
karim79
Yes that seems to be the problem, headers already sent, it says line 45 which is this; <meta http-equiv="Content-Type" content="text/html; utf-8" /> I don't see how to fix this yet
jasondavis
Weird thing is I have been doing it this way for a long time on this server and it just now quit working, thing is I include a header file and the redirect is getting called in the included file so I am not sure how to make it work since the header file is already printed out by the time it reaches my redirect
jasondavis
You can't have ANY output whatsoever before using header()
Mike B
+1  A: 

Also when you are using the header function it has to be the first thing called before any text (even a space) is written to the client, so check again that there is no spaces being output prior to your call even before th

<?php
Toby Allen
He isn't getting any errors. It would throw an error if this is the case.
Chacha102
A: 

What exactly happens when you visit the page? You can try Firebug or any other tool that allows you to analyze HTTP headers and check if the redirect really happens and whether the Location header is really present.

Adam Byrtek
A: 

You should also verify that you are redirecting to a valid location, and that the location has proper 404 and 500 error messages/pages setup. It could be that you are simply redirecting a bad place.

arbales