Php 404 Not Found Header

后端 未结 2 1094
自闭症患者
自闭症患者 2021-01-12 12:23

I am trying to understand the combination of 3 simple php code lines, This is the code:

ob_end_clean();
header(\'HTTP/1.0 404 Not Found\');
exit;
         


        
2条回答
  •  一个人的身影
    2021-01-12 12:37

    If i remove the first line and i got a BOM at the document i get blank page (No 404). you get blank 404 because you have no content defined in there...

    header('HTTP/1.0 404 Not Found');
    

    is only giving notice that user is on 404 error page site... if you want to display some 404 notice for user you can do this by loading your 404.html file

    if(strstr($_SERVER['REQUEST_URI'],'index.php')){
      header('HTTP/1.0 404 Not Found');
      readfile('404missing.html');
      exit();
    }
    

    or directly

    if (strstr($_SERVER['REQUEST_URI'],'index.php')){
        header('HTTP/1.0 404 Not Found');
        echo "

    Error 404 Not Found

    "; echo "The page that you have requested could not be found."; exit(); }

    exit function is there because you have to prevent execution of another php code, which may be directly after if or which may be excecuted later, simply it says END

提交回复
热议问题