/    Sign up×
Community /Pin to ProfileBookmark

custom 404 page with notification

Hi all

I’m using the following php code in my custom 404 page with a notification sent to my email with the error and requested page or file that was missing.

here is the code:

[code=php]
<?php
$emailaddress = “[email protected]”;
putenv(‘TZ=EST5EDT’); // eastern time
$errortime = (date(” F d h:ia”));
$browser = $_SERVER[‘HTTP_USER_AGENT’];
$domain = $_SERVER[‘HTTP_HOST’];
$page = $_SERVER[‘REQUEST_URI’];
$referer = $_SERVER[‘HTTP_REFERER’];
$IP = $_SERVER[‘REMOTE_ADDR’];
$message = “”;
$message .= “Time of the error: $errortimenn”;
$message .= “browser: $browsernn”;
$message .= “Page Requested: $domain$pagenn”;
$message .= “Referer: $referernn”;
$message .= “IP Address: $IPnn”;
$name = gethostbyaddr($IP);
$message .= “Hostname: $namenn”;
mail($emailaddress, “404 Error” , $message, “From: Website <>”);
?>
<html>
<head>
<title>404 – where oh where?</title>
<style type=”text/css”>
<!–
A:link {text-decoration: none; font-weight:bold; color: blue}
A:active {text-decoration: none; font-weight:bold; color: blue}
A:visited {text-decoration: none; font-weight:bold; color: blue}
A:hover {text-decoration: none; font-weight:bold; color: red}
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.style2 {
font-size: 30px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
}
–>
</style>
</head>
<body>
<table align=left width=100% border=0>
<tr>
<td>
<span class=”style2″>Not Found.<br>
<br>
</span>
<span class=”style1″>(oops)
<br>
<br>
it appears you were looking for:<br>
<FONT COLOR=teal>
<?=$domain?>
<?=$page?>
</font>
<br>
<br>
however, since you are here, it is clear you did not get what you wanted.
<br>
<br>
the problem has been reported so any broken links can be found and repaired.
<br>
<br>
you can click <a href=”javascript:history.go(-1)”>here</a> to go back to your previous page.<br>
<br>
</span>
<hr>
<span class=”style1″></span></td>
</tr></table>
</body>
</html>

[/code]

It works great accept I keep get this in an email:

[CODE]
Time of the error: September 24 11:40am

browser: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040707 Firefox/0.9.2

Page Requested: mydomainname.com/favicon.ico

Referer:

IP Address: 80.800.8.800

Hostname: host80-800-8-800.range80-800.btcentralplus.com
[/CODE]

this is the bit that gets to me: favicon.ico

I’m not using a favicon.ico so why is it saying the site is trying to find it?

if know one knows then how do I tell the script to ignore “favicon.ico” and not to send me the email.

also….how do I change the date in the script to be “GMT” time instead of “eastern time” ?

Cheers
Chris

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@pyroSep 24.2004 — How about this:

[code=php]if ($page != '/favicon.ico') {
mail($emailaddress, "404 Error" , $message, "From: Website <>");
}[/code]


As far as GMT time, take a look at [URL=http://www.php.net/gmdate]gmdate[/URL]
Copy linkTweet thisAlerts:
@cybercampbellauthorSep 24.2004 — Great!!! ? ? ? ? ? ?

Thanks

Chris
×

Success!

Help @cybercampbell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...