For beginners here is an example that will let you add audit code through your program then choose which audits get logged. helps keep your code clean as you can add as many adit calls as you want and the configure deals with them
<code>
// binary values
define ("AUDIT_NORMAL",1); // 00001
define ("AUDIT_DB_INSERT",2); // 00010
define ("AUDIT_DB_UPDATE",4); // 00100
define ("AUDIT_DB_EXTRACT",8); // 01000
define ("AUDIT_DB_DELETE",16); // 10000
// define some types of audit level
define ("AUDIT_JUST_DB", AUDIT_DB_INSERT + AUDIT_DB_UPDATE + AUDIT_DB_EXTRACT + AUDIT_DB_DELETE);
// 11110
define ("AUDIT_ALL",31); // all possible options
// 11111
define ("AUDIT_LEVEL",AUDIT_JUST_DB);// Choose the audit level to user
$GLOBALS["CODEX"]= Array(1 => "Normal", 2 => "DB_INSERT", 4 => "DB_UPDATE", 8 => "DB_EXTRACT", 16 => "DB_DELETE");
define ("LOG_PATH", "/temp/mylog");
/**
* Add an audit to the log
*
* Some Constants Used
*
* $GLOBALS["CODEX"] is an array of short descriptions for each audit type so that the log reads better.
*
*
* use and AND statement to compare the type of information you are wanting to audit and the level that you have told your program to record
*
* type, level
* AUDIT_NORMAL & AUDIT_LEVEL = 00000 ie 00001 & 11110 === 00000 ( Do not log )
* AUDIT_DB_UPDATE & AUDIT_LEVEL = 00100 ie 00100 & 11110 === 00100 ( Add to log )
* AUDIT_DB_INSERT & AUDIT_LEVEL = 00010 ie 00010 & 11110 === 00010 ( Add to log )
*
* So when you AND a interger with a MASK in this case the AUDIT_LEVEL
* @access public
* @author IrishAdo <irishado@hotmail.com>
* @param String Class you were in
* @param String Type of Audit information
* @param String Message
**/
public function __AddAudit($class, $typeof, $msg){
if ((AUDIT_LEVEL & $typeof)*1 === $typeof && AUDIT_LEVEL != AUDIT_NONE){
$path = LOG_PATH . date("Ymd.H") . ".audit.log";
$fp = fopen($path ,"a");
if($fp){
$usr = $_SESSION["name"];
$ip = $_SERVER["REMOTE_HOST"];
$file = $_SERVER["SCRIPT_NAME"];
fwrite($fp, "". $GLOBALS["CODEX"][$typeof]."\t" . Date("r") . "\t$ip\t$file\t$class\t$usr\t$msg\r\n");
fclose($fp);
} else {
print "Unable to write to file $path.";
exit();
}
}
}
</code>