dongzhuo7291 2018-05-18 03:21 采纳率: 0%
浏览 87

PHP标头位置不起作用/没有HTTP状态:更改

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 difference
  • header("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 duplicate

  • State of cgi.rfc2616_headers

  • PHP SAPI

  • Running the sample code outside the phar.

  • 写回答

2条回答 默认 最新

  • duanshaiduhao2471 2018-05-18 03:33
    关注

    Try this.

         header("Refresh: $seconds; URL=\"$location\"");  
    
    评论

报告相同问题?