Computing.Net > Forums > Web Development > 404 error page query

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

404 error page query

Reply to Message Icon

Name: ian_ok
Date: October 25, 2005 at 13:44:22 Pacific
OS: win xp 98 & 2k
CPU/Ram: p3 512
Comment:

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.html

AddType application/x-httpd-php .php .htm .html

Venta Sanlucar Sales



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: October 26, 2005 at 02:19:07 Pacific
Reply:

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


0

Response Number 2
Name: Laler
Date: October 26, 2005 at 09:38:18 Pacific
Reply:

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";


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


PHP Script Need help handling credit card in w...



Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: 404 error page query

Custom Error Pages www.computing.net/answers/webdevel/custom-error-pages/391.html

My PHP scripts constantly refresh. www.computing.net/answers/webdevel/my-php-scripts-constantly-refresh/961.html

Can't Access Website www.computing.net/answers/webdevel/cant-access-website/3800.html