PHP and Error Documents

They have: 334 posts

Joined: Dec 1999

I'm trying to customize my 404 Error page to let people notify me of bad links. I've written a basic PHP form mail script and embedded the code on the 404 page. What I want the thing to do is take the referring URL and the requested file, write them into the form text areas and have a "notify me" button under it. That'll make it a snap to find and correct bad links.

I've gotten everything to work except for one sticking point. The 404.php3 is always written into the $REQUEST_URI value in the following

code:

Code Sample: 

<TR> 
   <TD VALIGN="TOP"><TEXTAREA COLS="50" ROWS="2" NAME="textarea">Referring URL: <? print $HTTP_REFERER ?></TEXTAREA></TD>
  </TR>

  <TR> 
   <TD VALIGN="TOP"><TEXTAREA COLS="50" ROWS="2" NAME="textarea">Requested File: <? print $REQUEST_URI ?></TEXTAREA></TD>
  </TR>
 
[/code]


So it's returning the proper value for $HTTP_REFERER, but since the 404.php3 page is called for errors, that's the value that gets returned for $REQUEST_URI instead of the file that was actually requested. Is there any way to make the script hold the proper requested value instead of having that value overwritten when the 404 page is called?

BTW, I've also tried using $QUERY_STRING and $PATH_TRANSLATED in place of $REQUEST_URI, but to no avail. In every method the 404 error page always overwrites the originally requested file. 

They have: 5,633 posts

Joined: Jan 1970

Maverick,

Try using this

code:

<?php echo getenv(REQUEST_URI); ?>[/code]

Instead of this:

code:
<? print $REQUEST_URI ?>[/code]


That is what we use on our error pages that do what you would like (except the error e-mail is automatically e-mailed to us which is more effective than having a visitor push the "Notify" button). It should work.

------------------
Dynamic Internet Solutions :  http://www.dids.com 
Windows NT and UNIX Hosting 

They have: 334 posts

Joined: Dec 1999

Hmmm, okay, let's chalk this one up as "you learn something new and strange every day".

I tried your suggested code and it did the same thing as mine, just returning 404.php3 instead of the requested file name. However, the fact that it worked for you and not for me led me to delve deeper into the problem. I played around with a few things and found the real culprit. I had that one error document in my .htaccess file referenced as a full domain name (http://www.whatever.com/404.php3) instead of just a relative path of /404.php3. That, for whatever reason, was causing the $REQUEST_URI to be rewritten. I guess the way it accessed that file was adding an extra step into the equation and that step was the one that was getting logged. Or, if I'm wrong about that, maybe one of you Apache gurus can tell me what really happened.

Anyway, for
ErrorDocument 404 /404.php3

both <? print $REQUEST_URI ?> and <?php echo getenv(REQUEST_URI); ?> work fine

for
ErrorDocument 404 http://www.domain.com/404.php3

neither code works. Thanks for the help Chad.

They have: 5,633 posts

Joined: Jan 1970

That is strange... I didn't even think about it being refrenenced like that. I am not an Apache guru so don't look at me for an answer, though I will see what I can find as it is curious.

Glad you got it working though.

------------------
Dynamic Internet Solutions : http://www.dids.com
Windows NT and UNIX Hosting

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.