Headers are not redirected (and no errors)

This is a very strange problem. In my code, I have a redirect that works fine on my local server.

header("location:/sign-up-success"); 

When I click on production, it just doesn't redirect. Is there a parameter that I am missing?

I even tried:

 header("Location: https://www.myurl.com/sign-up-success"); 

It seems to just skip the redirect. Any ideas?

+6
source share
4 answers

Thanks for all the answers. Apparently the answer to this question was given by @netcoder in the comments. The answer is below:

In the php.ini file on my local computer, I had "output_buffering = 4096", and on the production server it was set to "output_buffering = off". By turning it on, we fixed the problem with the header and some other problems.

For those who have problems with other headers, check out the other answers as they will be useful if you turn off the error report. (I used to come across this, so I knew that this was not a problem, but it could be a headache for people working with forwarding, and not knowing what the problem was).

Thanks to everyone.

0
source

possible reason: you sent some output to the browser before calling header()
: write ob_start() at the top of the page

Best practice: alwyas write exit() after header() ..

Link

+2
source

Look at the error_reporting value on the production server. If it is set too low, nothing will be logged, because errors of a lower level than error_reporting are simply ignored. The same applies to using @ - it sets error_reporting to 0, so if something bad happens (for example, if a function is not even defined), you will not see anything in the log.

From what you wrote about enabling output buffering, it seems that you have some output before header() (that's why activating output buffering helps) and that your error_reporting set to 0 (that's why the warning “Can not change header information” not reported / not recorded).


On a side note ... To get maximum error information:

  • set error_reporting to E_ALL | E_STRICT E_ALL | E_STRICT (both in dev and in production)
  • enable error logging (critical for the production environment, although this would not hurt if it were enabled in the dev environment)
  • set display_error to true in the dev environment, false in the working environment (critical !!! the user should not see any PHP warnings / notifications / errors)
  • In addition, you can set_error_handler() to output or write more information than the default error handler (for example, you might want to save debug_backtrace() when an error occurs)
+2
source

It seems to just skip the redirect.

You need to take a look at what the script returns in the headers / content. Many tools are available for this: HTTP fiddler, iehttpheaders for MSIE, for Firefox there are tamperdata, liveheaders, a web developer toolbar and much more. Or sniff network traffic (although ssl decoding may be PITA)

0
source

Source: https://habr.com/ru/post/887156/


All Articles