========== 7. Now browse to your website / blog home page making sure everything is still running as it should 8. The first run will create the directory and the txt file 9. Any changes made to the .htaccess file from now on, will trigger an ALERT email to the owner. 10 To check it out for yourself, after uploading & including this file into the website, upload a copy of your local .htaccesss file back on the server (MAKE SURE YOU HAVE THE LATEST COPY FROM THE SERVER), then navigate to the home page of your website / blog If everything is running as it should, an email will be sent to the address you have entered bellow. =========== */ // CONFIGURATION $ewd_dir = dirname(__FILE__)."/"; //directory $ewd_look_for = ""; //file to look for $ewd_ext = array( '.htaccess'); //extensions to look for $ewd_dir_mk = false; //DO NOT CHANGE $ewd_flag = false; //DO NOT CHANGE $ewd_make_txt_dir = "_ht_txt_ewd"; //create directory for the txt file that will hold the filetime $ewd_txt_file_name = "_ewd_txt.txt"; // name of the txt file created $ewd_email = "info@eire-webdesign.ie"; //email will be sent to $ewd_subject = "Eire-WebDesign.ie .HTACCESS MODIFIED"; //email subject // LET'S CREATE THE DIRECTORY if(!is_dir($ewd_dir . $ewd_make_txt_dir)){ //echo "directory doesn't exist
"; if(mkdir($ewd_dir . $ewd_make_txt_dir, 0755)){ $ewd_dir_mk = true; //echo "DIRECTORY CREATED
"; }else{ $ewd_dir_mk = false; //echo "CAN NOT CREATE DIRECTORY
"; } }elseif(is_dir($ewd_dir . $ewd_make_txt_dir)){ $ewd_dir_mk = true; } //CREATE TXT FILE if($ewd_dir_mk){ if( !file_exists( $ewd_dir . $ewd_make_txt_dir . "/" . $ewd_txt_file_name ) ) { $ewd_fp = fopen($ewd_dir . $ewd_make_txt_dir . "/" . $ewd_txt_file_name, "w"); fclose($ewd_fp); //echo "TXT FILE CREATED
"; } } //RUN THE CHECK for( $i = 0; count( $ewd_ext ) > $i; $i++ ){ if( file_exists( $ewd_dir . $ewd_look_for . $ewd_ext[$i] ) ) { $ewd_flag = true; $ewd_name = $ewd_look_for . $ewd_ext[$i]; $ewd_file_time = filemtime($ewd_dir . $ewd_look_for . $ewd_ext[$i]); echo 'File Found: '.$ewd_look_for.$ewd_ext[$i]." - last modified: ".date ("F d Y H:i:s.", $ewd_file_time)."
";//UNCOMMENT IF TESTING //GET FILE CONTENTS $ewd_last_time = file_get_contents($ewd_dir . $ewd_make_txt_dir . "/" . $ewd_txt_file_name); //echo $ewd_last_time."
"; //UNCOMMENT IF TESTING if($ewd_last_time != ""){ $ewd_check_time = explode("|",$ewd_last_time); if($ewd_file_time != $ewd_check_time[1]){ //CHANGES WERE MADE - SEND ALERT EMAIL AND LOG THE NEW TIME $ewd_headers = "Content-type: text/plain\r\n"; $ewd_headers .= "From: $ewd_email\r\n"; $ewd_message = "The .htaccess has been modified\r\n". "STORED DATE/TIME: " . date ("F d Y H:i:s.", $ewd_check_time[1])."\r\n". "MODIFIED DATE/TIME: " .date ("F d Y H:i:s.", $ewd_file_time)."\r\n"; mail($ewd_email, $ewd_subject, $ewd_message, $ewd_headers); //LOG THE NEW DATE / TIME $ewd_fp = fopen($ewd_dir . $ewd_make_txt_dir . "/" . $ewd_txt_file_name, "w"); fwrite($ewd_fp, $ewd_look_for.$ewd_ext[$i]."|".$ewd_file_time); fclose($ewd_fp); } }else{//LOG THE TIME & DATE FOR THE FIRST TIME RUN $ewd_fp = fopen($ewd_dir . $ewd_make_txt_dir . "/" . $ewd_txt_file_name, "w"); fwrite($ewd_fp, $ewd_look_for.$ewd_ext[$i]."|".$ewd_file_time); fclose($ewd_fp); } } } ?>