Reputation: 219
This is a very strange issue. In my code I have a redirect that works perfectly on my local server.
header("location:/sign-up-success");
When I push to production, it just doesn't redirect. Is there a setting that I am missing?
I have even tried:
header("Location: https://www.myurl.com/sign-up-success");
It appears to just skip over the redirect. Any ideas?
Upvotes: 6
Views: 158
Reputation: 219
Thank you for all the responses. It appears the answer to this question was given by @netcoder in the comments. The answer is found below:
In the php.ini file on my local machine I had "output_buffering = 4096" and on the production server it was set at "output_buffering = off". Turning it on fixed the header issue and some other problems as well.
For those with other headers problems, please review the other responses as they will be helpful if you have error reporting turned off. (I had run into that before, that's why I knew that wasn't the problem but that can certainly be a headache for people working with redirects and not knowing what the problem is).
Thank you all.
Upvotes: 0
Reputation: 9122
Take a look at value of error_reporting
on production server. If it is set to too low level, there will be nothing in the log, as errors of lower level than error_reporting
are just silently ignored. Same applies to using @
- it sets error_reporting
to 0, so if anything bad happens (e.g., if function is not even defined), you won't see anything in the log.
From what you wrote about enabling output buffering, it seems that you have some output before header()
(this is why enabling output buffering helps) and that your error_reporting
is set to 0 (this is why warning about "Cannot modify header information" was not being reported/logged).
On a side note... To get the most of error reporting:
error_reporting
to E_ALL | E_STRICT
(in both dev and production environments)display_error
to true
in dev environment, false
in production environment (critical!!! user does not have to see any PHP warnings/notices/errors)set_error_handler()
to output or log more information than default error handler does (e.g., you might want to store debug_backtrace()
, when error occurs)Upvotes: 2
Reputation: 54016
possible reason: you have sent some output to the browser before the call of header()
solution : write ob_start()
at the top of the page
Best practice : alwyas write exit()
after header()
..
Upvotes: 2
Reputation: 48357
It appears to just skip over the redirect.
You need to have a look at exactly what the script is returning in headers / content. There are lots of tools available for this - HTTP fiddler, iehttpheaders for MSIE, for Firefox there's tamperdata, liveheaders, web developer toolbar and many more. Or sniff the network traffic (though decoding ssl can be a PITA)
Upvotes: 0