I have tried to attach this code as an attachment, but some how I cannot do it, comes back invalid file. Anyway I have to drop it in here.
If Intelligent 404 doesn’t find the page it was looking for, it will simply redirect the surfer to your home page. The delay is currently set to three seconds.
1. Open 404.php
2. Edit $host - change to your web address
3. Edit $email - change to your email address
4. Edit $emailsPerDay - default is 25
5. Edit $checkRobots - 0 is off and 1 is on
6. Resave changes
7. Upload four files to server
8. Chmod 404.db to 777
Will this code work with Zencart?
PHP Code:<?php
$extensions = "htm,html,php,shtml"; // extensions to check for, last one will take overrule the first
$serverpath = ".";
$host = "www.yoursite.com";
$email = "[email protected]";
$email_subject = "404 error at $host";
$etoday=date("m-d-Y[H:i:s]");
$pause = 1; // do not wait, redirect visitor immediately
$pauseTime = 3; // in seconds
$emailsPerDay = 25; // maximum number of daily emails
$checkRobots = 0; // '1' ==> send email or '0' ==> no email if spider gets an invalid page
$redirectNote ="<center style='font-family: tahoma;'><h3>(404)</h3>The page you requested is non existant.<br>
In $pauseTime seconds you will be redirected.</center>";
$pages[1] = 'http://'.$host.'/'; // page to redirect to if no substitute is located
// ########### DO NOT MODIFY BELOW UNLESS YOU KNOW WHAT YOU ARE DOING############## //
$extensions = explode(",", $extensions);
$num_pages=count($pages);
if($num_pages!=1){
if($efof!=$num_pages){$efof+=1; }else{$efof=1; }
}else{$efof=1;}
$dom=".".$host;
setcookie("efof","$efof","0","/","$dom","0");
$today=date("d-m-Y[H:i:s]");
$requested=getenv("REQUEST_URI");
$req_url="http://".$host.$requested;
$referer=getenv("HTTP_REFERER");
if($referer==""){$referer="n/a"; }
if(getenv("HTTP_CLIENT_IP")) {
$ipaddr = getenv("HTTP_CLIENT_IP");
} elseif(getenv("HTTP_X_FORWARDED_FOR")) {
$ipaddr = getenv("HTTP_X_FORWARDED_FOR");
} else {
$ipaddr = getenv("REMOTE_ADDR");
}
$agent=getenv("HTTP_USER_AGENT");
$from="alert404@".$host;
/* ingore robot string */
$igstring=0; $igrobots=0; $User="User";
/* web spider check */
if(eregi("robots.txt",$req_url)){
if($checkRobots==1){$igrobots=0; $robotfound=1; $User="Robot"; }
else{$igrobots=1; }
}
/* ignore processor? */
if(file_exists("ignore.txt")){
$currentfile=file("ignore.txt");
while(list($num,$line)=each($currentfile)){
$line=chop($line); $req_url=chop($req_url);
if(ereg("$line","$req_url")){$igstring=1; }
if(ereg("$line","$agent")){$igstring=1; }
if(ereg("$ipaddr","$line")){$igstring=1; }
}
}
$filename=basename("$requested");
$dirname=dirname("$requested");
$name=explode(".",$filename);
$ext=$name[1];
$name=$name[0];
$atom_lth=strlen($name)-1; $atom_lchar=substr($name,-1);
if($atom_lchar!="s"){$nameplural=$name."s"; }else{$nameplural=$name; }
if($atom_lchar=="s"){$namesingular=substr($name,0,$atom_lth); }else{$namesingular=$name; }
$homedir=$serverpath.$dirname;
if($dirname=="/"){$dirname=""; }
foreach ($extensions as $ext) {
//print "$homedir/$namesingular.$ext";
if(file_exists("$homedir/$nameplural.$ext")){ $urlR="http://".$host.$dirname."/".$nameplural.".".$ext; }
if(file_exists("$homedir/$namesingular.$ext")){$urlR="http://".$host.$dirname."/".$namesingular.".".$ext;}
}
if($urlR!=""){$rdto="Redirected to: $urlR";}
$mesg = "Date: $etoday\n$User request for: $req_url was not found!\nIP address: $ipaddr\nBrowser: $agent\nReferred by: $referer\n$rdto\nError Code: 404\n ";
$fd = fopen("404.db", "r");
if(!$fd) {
$errmsg="Please create a \"404.db\" file and upload to your server.\nchmod the file to \"777\" - otherwise, the script will NOT work correctly";
mail($email,"Error - 404.db not found","$errmsg","From: system@$host");
exit();
}
flock($fd,2);
while (!feof ($fd)) { $buffer = fgets($fd, 1024); }
list($ctr,$date)=explode("|",$buffer);
$ctr=trim($ctr);
$today=date("d-m-Y");
if($date==$today) {
if($ctr >= $emailsPerDay) { $stopmail=1;
}
else { $ctr=$ctr+1;
$stopmail=0;
}
} else {
$date=$today;
$ctr=1;
$stopmail=0;
}
flock($fd,3);
fclose ($fd);
if($stopmail == 0) {
if($igstring==0 && $igrobots==0) {
$fd = fopen ("404.db", "w");
$bdy="Please \"chmod 777\" the \"404.db\" file";
if(!$fd){
mail("$email","404.db is not writable.","$bdy","From: system@$host");
exit();
}
flock($fd,2);
$datstr=$ctr . "|" . $date;
fputs($fd,$datstr);
flock($fd,3);
fclose ($fd);
if($robotfound) { mail("$email","Spider robot detected","$mesg","From: $from"); }
else {mail("$email","$email_subject","$mesg","From: $from"); }
}
}
if($urlR != "") {header("Location:$urlR");
exit();
}
$url = $pages[$efof];
if($pause){ echo "$redirectNote";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"$pauseTime ;URL=$url\">";
} else { header("Location:$url");
exit();
}
?>


Reply With Quote
