Hi,

I have some code which takes a variable from GET and uses it to generate the name of the file to include - for example, going to index.php?area=home means that index.php then includes home.php. I've created a piece of code which takes this filename and searches the directory for it. If it doesn't exist, it executes a redirect to my custom 404 page.

The problem is that it is currently just using Header (Location: 404.php). Since my 404 sends an email to me everytime with the bad link, whenever this happens it tells me that the bad link was 404.php itself. Including the file results in a blank page. Is there some way I can generate a real 404, like you get when a page doesn't actually exist?

    You can try using the $_SERVER['HTTP_REFERRER'] var on the 404.php page.

      there are two examples of sending a 404 on php.net
      php.net header

      you will then need to set the default 404 page in your config
      or use a htaccess file
      use the relative url
      ErrorDocument 404 /folder/404.php

      and then you will find
      $_SERVER['REQUEST_URI']
      holds the original requested page

        a month later

        Thank you for this answer. It indirectly solved my problem too!

        WAP browsers generally will not display the message in the 404.php file if apache replies with 404. Through your answer I figured out to send a

        header("Status: 200 OK");

        at the beginning of 404.php to prevent the WAP browser from displaying the generic "file not found" error. Happy Happy Joy Joy!

        Thanks again!😃

          Write a Reply...