PHP如果“id”null移动到url

Need assistance with the following code, i have a form providing a "id", when submitted the next script gets the data from the database, if for some reason the "id" is zero, how can i forward the url to my 404 page.

Code:

$id=$_GET['id'];
        include ('dbconnection.php');
        include ('dbopen.php');
        include ('header.php'); 

I have tried the following, but no success to move client to the 404.php page if "id" value is null.

if (isset($_GET['id']) && !empty($_GET['id'])) {

  header('Location: index.php');
}

Please help :D

Use this:

if (!isset($_GET['id']) || empty($_GET['id'])) {
    header('Location: 404.php');
    exit(); // don't execute any code after it!
}

Your code should work. But there shouldn't be any output (echo or content out of ) before header.