Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
When my 404 error page appears it send me an email, with the linking page, but If someone types in www.domain.com/hjdbjhs.html (which isn't available) I don't find out what they typed in.
How can I work this out?
This is my code for 404 page
<?php$count = 0;// don't send mail if we don't know the referring page// it's probably a searchengine or infected windows system requesting known NT server exploits// may reinstate but wana know if works//if ($HTTP_REFERER == "")//{//$count++;//}// debug comment, you can remove this line if you want:echo "\n";if ($count == 0){$today = date("j F Y, G:i:s");$message = "Date and Time: $today\nRequest URL: http://$SERVER_NAME$REQUEST_URI\nReferring page: $HTTP_REFERER\n\nClient: $HTTP_USER_AGENT\nRemote IP: $REMOTE_ADDR\n\n";$message .= "This is an automated message.\n\nIan.";mail("email@domain.com", "Error 404", $message, "From: email@domain.com\nReply-To: email@domain.com");}?>This is my .htaccess file:
ErrorDocument 404 http://www.domain.com/404.htmlAddType application/x-httpd-php .php .htm .html

Ouch, where's the newlines :P
I think the above script will not send the email when no referrer defined, so you don't get mails when you typed www.domain.com/hjdbjhs.html instead of just not getting the referrer page?
:::::
There's $count = 0 with comment, "dont send mail if no referrer", and on the middle there's: if ($count = 0)...
So you might want to try to change
$count = 0;
into
$count = 1;
Then the email will be sent on each pageload.
To get what the visitor type, you can add this at the bottom (somewehere near $HTTP_USER_AGENT\n):
$_SERVER['REQUEST_URI']\n

err, sorry.
Here's a script to send all details to your e-mail:
<?php
$count = 1;
$report = print_r ($_SERVER, TRUE);
if (!empty ($_SERVER['HTTP_REFERER']))
{
$count = 1;
}
if ($count != 0)
{
mail ("yourmail@domain.com", "Automated Report", $report);
}
?>If you want only people who have "referrer" that will trigger the mail(), replace $count = 1; into $count = 0;
And if you want only a few details got recorded (as in your script above), replace:
$report = print_r ($_SERVER, TRUE);</font
into:
$report = "Date and Time: $today\nRequest URL: http://$SERVER_NAME$REQUEST_URI\nReferring page: $HTTP_REFERER\n\nClient: $HTTP_USER_AGENT\nRemote IP: $REMOTE_ADDR\n\n";

![]() |
PHP Script Need help
|
handling credit card in w...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |