Jump to content

Recommended Posts

Hi,

 

I would like to be able to receive and emain on what pages users are getting 404 errors (or any other for that fact).

 

I have the directive in my .htaccess to redirect missing pages to my custom 404.php page.

 

However, despite trying a number of tutorial on how to get it to email me the url they tried to access, I can not get it to work.

 

My code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Please Wait</title>
<meta http-equiv="refresh" content="0; url=http://www.mysite.co.uk" />
</head>

<body>
<?PHP

$ip = getenv ("REMOTE_ADDR");
$requri = getenv ("REQUEST_URI");
$servname = getenv ("SERVER_NAME");
$combine = $ip . " tried to load " ;
$url = $servname . $requri ;
$httpref = getenv ("HTTP_REFERER");
$httpagent = getenv ("HTTP_USER_AGENT");
$today = date("D M j Y g:i:s a T");
$message2 = "On $today, $combine:\n
http://www.$url\n
User Agent = $httpagent \n
$httpref ";
$to = "my.email@domain.com";
$subject = "404 Error Report";
$from = "From:no-reply@domain.com\r\n";
mail($to, $subject, $message2, $from);


?>
</body>
</html>

 

I just get:

 

On Mon Jan 16 2012 9:55:57 am UTC, 82.153.239.221 tried to load :

 

http://www.www.mysite.co.uk/404.php

 

User Agent = Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; .NET CLR 2.0.50727; .NET CLR 3.5.30729)

 

Link to comment
https://forums.phpfreaks.com/topic/255131-404-error-detection/
Share on other sites

try doing this:

 

var_dump($_SERVER);

 

and look thru the server variables for a value that may better accommodate your needs...

 

You could peer into the log files, you should be able to see where the logs are stored by checking out your httpd.conf file from apache, or contacting your hosting provider to tell you where they're stored, you should also be able to format your errors to show IP addresses and dates, so you can use the request time and the IP address to get a relatively good idea of which error belongs to which user.. and can email from there..

 

But the second alternative is only if $_SERVER doesn't give you the information you need, I haven't done much custom error pages, especially with emailing of problems, but those 2 places are a good place to start looking :)

Link to comment
https://forums.phpfreaks.com/topic/255131-404-error-detection/#findComment-1308112
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.