404 email alert

Here is a little PHP code snippet to add to your 404 page, in order to get an email alert with all sorts of useful data, each time a 404 page is accessed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if(isset($_SERVER['HTTP_REFERER'])) {
    $ref=$_SERVER['HTTP_REFERER'];
}
else{
	$ref='none';
}
 
$sitename='Reflection Media';
 
$recipient = 'mail@gmail.com';
$subject = 'New '.$sitename.' 404 accessed';
$mail_body = '
A new 404 page has been accessed:
 
The accessed URI was: '.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'
The user's IP address: '.$_SERVER['REMOTE_ADDR'].'
The user's Internet browser: '.$_SERVER['HTTP_USER_AGENT'].'
The URI from where your user came: '.$ref.'
';
$header = 'From: '.$sitename.' 404 page <no-reply@mail.com>rn';
 
mail($recipient, $subject, $mail_body, $header);
This entry was posted in PHP and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted August 11, 2009 at 12:11 am | Permalink

    Is there a bus to the castle?
    —————————————
    signature: buy xenical f6ef8e8efe2h9045999g

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*