PHP, MVC, 404 - How can I redirect to 404?

Posted by Doug on Stack Overflow See other posts from Stack Overflow or by Doug
Published on 2010-06-16T02:49:24Z Indexed on 2010/06/16 2:52 UTC
Read the original article Hit count: 274

Filed under:
|

I'm trying to build my own MVC as a practice and learning experience. So far, this is what I have:

<?php
require "config.php";

$page = $_GET['page'];
if( isset( $page ) ) { 
    echo "isset is true";
    if( file_exists( MVCROOT . "/$page.php" ) ) {
        include "$page.php";
    } else {
        header("HTTP/1.0 404 Not Found");
    }
}


?>

My problem here is, I can't use header to send to a 404 because the headers have been send already. Should I just redirect to a 404.html or is there a better way? Feel free to critique what I have so far (it's very little). I would love suggestions and ideas. Thanks!

© Stack Overflow or respective owner

Related posts about mvc

Related posts about php5