PHP header redirect not working

前端 未结 13 2116
小蘑菇
小蘑菇 2020-12-05 12:00

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         


        
13条回答
  •  悲哀的现实
    2020-12-05 12:37

    COMMON PROBLEMS:

    1) there should not be any output (i.e. echo.. or HTML codes) before the header(.......); command.

    2) there should not be a white-space(or newline) before and after ?> tags.

    3) GOLDER RULE! - the file (and other include()-d files) should have UTF8 without BOM encoding (and not just UTF-8). That is problem in many cases (because typical UTF8 encoded file has something special character in the start of file output)!!!!!!!!!!!

    4) When redirecting, after header(...); you must use exit;

    5) Recommended practice - always use 301 or 302 in reference:

    header("location: http://example.com",  true,  301 );  exit;
    

    6) If none of above helps, use JAVSCRIPT redirection(but it's highly not recommended By Google), but it may be the last chance...:

    echo ""; exit;
    

提交回复
热议问题