views:

55

answers:

1

Hello all,

I'm working with a PHP site that needs to log errors to a database. As such, I've set up a .htaccess file as follows:

ErrorDocument 404 /404.php

404.php contains all of the logging functions necessary to insert the log into the database. What I'm having problems with is retrieving the URL of the file that triggered the 404.

Here are the contents of the $_SERVER superglobal array:

[HTTP_HOST] => {omitted}
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip,deflate
[HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[HTTP_KEEP_ALIVE] => 300
[HTTP_CONNECTION] => keep-alive
[PATH] => /usr/local/bin:/usr/bin:/bin
[SERVER_SIGNATURE] => 
[SERVER_SOFTWARE] => Apache/2.2.8 (Ubuntu)
[SERVER_NAME] => {omitted}
[SERVER_ADDR] => {omitted}
[SERVER_PORT] => 80
[REMOTE_ADDR] => {omitted}
[DOCUMENT_ROOT] => {omitted}
[SERVER_ADMIN] => [no address given]
[SCRIPT_FILENAME] => /404.php
[REMOTE_PORT] => 19274
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => 
[REQUEST_URI] => /404.php
[SCRIPT_NAME] => /404.php
[PHP_SELF] => /404.php
[REQUEST_TIME] => {omitted}

Any suggestions? Everything that I've read recommends the HTTP_REFERER item, but it doesn't seem to exist.

Thanks in advance.

+3  A: 

REQUEST_URI is meant to contain the requested URL path and query.

Gumbo
I am aware of this. However, as shown above, REQUEST_URI returns the 404.php path and not the original request (for example nonexistentfile.php). Are there perhaps directives I can add to the .htaccess file that would prevent the client from being redirected?
Warren
This is the correct answer. It appears that REQUEST_URI will not contain the referrer unless the ErrorDocument is a relative file (no absolute URLs).Thanks!
Warren
@Warren: If you specify an absolute URL as your error document, the server will respond with a 302 status code (redirect) instead of a 404.
Gumbo