I have this as my 404 page, I used htaccess to designate it. It first sees if the 404 is from favicon.ico. If not it continues. It then checks to see if the http agent is from a bot, if not then it emails me the info. But there must be a more efficient way of doing this. Any help?
if ($_SERVER['REQUEST_URI'] != 'favicon.ico') {
$IP = $_SERVER['REMOTE_ADDR'];
$uri1 = $_SERVER['HTTP_HOST'];
$uri2 = $_SERVER['REQUEST_URI'];
$URi = $uri1.$uri2;
$ag = $_SERVER['HTTP_USER_AGENT'];
$refcx = $_SERVER['HTTP_REFERER'];
$swp = '/bot/i';
if (preg_match($swp, $ag)) {
$swb = 1;
} else {
$swb = 0;
}
$swp1 = '/yahoo-test-fetch/i';
if (preg_match($swp1, $ag)) {
$swb1 = 1;
} else {
$swb1 = 0;
}
$swp2 = '/findlinks/i';
if (preg_match($swp2, $ag)) {
$swb2 = 1;
} else {
$swb2 = 0;
}
$swp3 = '/Yahoo! Slurp/i';
if (preg_match($swp3, $ag)) {
$swb3 = 1;
} else {
$swb3 = 0;
}
$swp4 = '/PowerBuilder/i';
if (preg_match($swp4, $ag)) {
$swb4 = 1;
} else {
$swb4 = 0;
}
$swp5 = '/Yoono/i';
if (preg_match($swp5, $ag)) {
$swb5 = 1;
} else {
$swb5 = 0;
}
if ($swb == 0 && $swb1 == 0 && $swb2 == 0 && $swb3 == 0 && $swb4 == 0 && $swb5 == 0) {
$adminintro = "---------------------------------------------------------\nMySite.com Admin Services\n---------------------------------------------------------\n";
$admincontent = $adminintro."IP Address: ".$IP."\nPage: ".$URi."\nAgent: ".$ag."\nRefer: ".$refcx;
$adminheader = "From: MySite.com Admin Services\r\n";
$adminsubject = "MySite.com 404";
$adminemail = "errors@MySite.com";
mail ($adminemail,$adminsubject,$admincontent,$adminheader);
}
}
print 'Error 404: Page Not Found'