Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    377
    Thanks
    8
    Thanked 1 Time in 1 Post

    Trigger an Error404 with PHP

    Hello,

    I need to produce an Error 404 with PHP.

    I want some users be able to access the file.php (based on their permissions) if they are allowed to.

    For the ones who don't have access to file.php, I don't want to display a "You are not allowed" kind of message, but an Error 404, as if the file does not exist.

    How can I do that? I don't want to use the header command to another file, since it would display the name of the second file in the address bar.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,862
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    See http://in.php.net/header,
    Code:
    <?php
    header("HTTP/1.0 404 Not Found");
    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    377
    Thanks
    8
    Thanked 1 Time in 1 Post
    Thanks for the suggestion.

    Unfortunately, it does not produce a Error 404 for me, but a blank page instead. What could be the problem?

    What about

    PHP Code:
    <?php

    header
    ("Location: nonexistent404.php");

    ?>
    and produce a real 404 error?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •