I would like to make a php script output like a real 404 page (as set in the Apache ErrorDocument directive) if certain conditions are not met. I\'m not sure how I can / if
Your example seems good. You need to use the php header function to do that:
Like that you're saying that this page is a 404, and you can then fill in the contents with what you want
A real 404 is just any piece of code that send's a 404 error code back to the browser, so ErrorDocument or header(..404...) are equivalent in this regard.