404 error page
Moderator: General Moderators
404 error page
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.
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
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