I'm facing a problem using Headers in PHP. header('location: http:google.com');
is not working. This is my code:
if(!headers_sent()){
header("location: http://google.com");
exit;
}
HTML Data...
Script is exiting but header()
is not working.
- I've already checked in my php.ini for
output_buffer
param and it's set to 4096. - There are not extra lines above PHP opening tag
- and my script is encoding in UTF-8 w/o BOM.
- All errors are enabled but I'm getting no errors/warnings/notices. What is happening?
- Environment: PHP 7.0.27 and NGINX.
Later attempts and debugging steps concluded:
header("location: http://google.com";, true, 302);
made no differenceheader("Refresh: ...")
did succeed.HTTP response debugging (after being asked a couple of times):
StatusCode : 200 StatusDescription : OK Content : <br /> <b>Notice</b>: Undefined index: HTTP_ACCEPT_LANGUAGE in ... RawContent : HTTP/1.1 200 OK Transfer-Encoding: chunked Connection: keep-alive Pragma: no-cache Cache-Control: no-store, no-cache, must-revalidate Content-Type: text/html; charset=UTF-8 Date: Fri, 18 May 201... Forms : {} Headers : {[Transfer-Encoding, chunked], [Connection, keep-alive],
Unanswered still:
header("Status: 303 etc");
vs.header('HTTP/1.1 301 Moved Permanently');
from the duplicateState of
cgi.rfc2616_headers
PHP SAPI
Running the sample code outside the phar.