404 error page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sanjayk
Forum Newbie
Posts: 2
Joined: Thu Aug 07, 2003 11:09 pm
Location: India

404 error page

Post by sanjayk »

I can assign a page for 404 errors on my web site. I want to make this page a .php page and want it to log exact error URL to some file. I will appreciate some hints. Thanks.
dataangel
Forum Newbie
Posts: 12
Joined: Thu Aug 07, 2003 7:29 pm

Post by dataangel »

You can get the error URL by using $PHP_SELF

It automatically stores the path to whatever page is being viewed.
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post by macewan »

create a .htaccess file with this:
ErrorDocument 404 404.php

create the 404.php with this in it:

<?php
$ip = getenv ("REMOTE_ADDR");
$requri = getenv ("REQUEST_URI");
$servname = getenv ("SERVER_NAME");
$combine = $ip . " tried to load " . $servname . $requri ;
$httpref = getenv ("HTTP_REFERER");
$httpagent = getenv ("HTTP_USER_AGENT");
$today = date("D M j Y g:i:s a T");
$note = "some more text that can be used" ;
$message = "$today \n
<br>
$combine <br> \n
User Agent = $httpagent \n
<h2> $note </h2>\n
<br> $httpref ";
$message2 = "$today \n
$combine \n
User Agent = $httpagent \n
$note \n
$httpref ";
$to = "you@yourwebsite.com";
$subject = "yourwebsite.com Error Page";
$from = "From: errorreport@yourwebsite.com\r\n";
mail($to, $subject, $message2, $from);
echo "
put your custome error in here.
" ;
?>


this will email you each time someone tries to access a missing page
sanjayk
Forum Newbie
Posts: 2
Joined: Thu Aug 07, 2003 11:09 pm
Location: India

Post by sanjayk »

This is exactly what I was looking for. I appreciate it.

Thanks!
Sanjay
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post by macewan »

=)
Post Reply