Re: Capturing 404s with PHP, slight twist

From: Date: Fri, 23 May 2003 14:46:48 +0000
Subject: Re: Capturing 404s with PHP, slight twist
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148774@lists.php.net to get a copy of this message
At 16:40 23.05.2003, Jeff Lewis said: --------------------[snip]-------------------- >I have created some custom error pages in PHP and am using htaccess to get >the pages to display. It works great when someone goes to a page that >doesn't exist. It's recording the information I want about errors so that I >can track things down and fix them. > >However, a small little quirk has popped up. > >If I go to a page http://www.mysite.com/player.html and the page >exists but >an image is missing, it logs the 404 page as the play.html and not the image >missing. > >By reporting, it records the referer as correct, but how can I get it to >return the actual file that caused the 404 error (in this case, an image)? > >I checked the $_SERVER and $_ENV variables but there doesn't appear to be >what I'm looking for unless I am missing something. --------------------[snip]-------------------- Recheck the $_SERVER array in the error handler. When called as error handler, the relevant array entries are set as this: [REDIRECT_ERROR_NOTES] => File does not exist: /home/user/www/stuff/demo.doc [REDIRECT_REQUEST_METHOD] => GET [REDIRECT_STATUS] => 404 [REDIRECT_UNIQUE_ID] => PmfkMT50HtMAABifETo [REDIRECT_URL] => /stuff/demo.doc You can check the ['REDIRECT_URL'] entry for the actual file that was missing. If it contains any image extension, e.g., you may serve a default image: if (preg_match('/\.(jpg|gif|png)$/i', $_SERVER['REDIRECT_URL'])) { // this was an image file } -- >O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/

« previous php.general (#148774) next »