Re: the issue of not getting a 404:
Here's what I use:
exit() makes sure nothing else goes out after the 404 header.
header("HTTP/1.0 404 Not Found");
Also you must ensure that nothing gets sent to the browser before the header() call. Look for echo() and print() before the header() calls.