-3

I am creating a back office website , and need to trace the operations done on the website , for that I need a to generate a log file of every operation for example : Date-Time -User-Operation. I have tried files but did not really work

$query_add="UPDATE auth_table SET etat = replace(etat,'$anc','$nv') where user_id LIKE  
'%$log%'";
$query_exec=mysql_query($query_add) or die(mysql_error()); 
?><script language='JavaScript'>alert('Activation termine')</script><?
$date = date("Y-d-m"); 
$heure = date("H:i"); 
$op=$date.$heure.'Activation du compte de'.$log.'par administrateur'.$logad; 
$fp = fopen('log.txt', 'w');
fseek($fp,0);
fputs($fp, $op);
fclose($fp);

Any idea on how to do this ?

DRYRA
  • 47
  • 1
  • 10
  • 1
    Search and you will find starting points: http://stackoverflow.com/questions/9096470/atomically-appending-a-line-to-a-file-and-creating-it-if-it-doesnt-exist – nickhar Apr 06 '13 at 19:14
  • @Daryl Gill : I will update the question to show you what I have tried so far. – DRYRA Apr 06 '13 at 19:17
  • alternatively instead of LOG files, why not use DATABASE as a store point of all processes, LOG files are for core applications and not web applications...how do you LOG files people accessing your web?...think about it...or your tags must vb/c++/c#/java ? – NosiaD Apr 06 '13 at 19:18
  • http://www.redips.net/php/write-to-log-file/ – auicsc Apr 06 '13 at 19:21
  • I think I will just do that . thank you – DRYRA Apr 06 '13 at 19:22
  • I would consider using apache on .htaccess http://www.webreference.com/programming/Apache-Logging/index.html – Nik Drosakis Apr 06 '13 at 19:29

1 Answers1

1
$query_add="UPDATE auth_table SET etat = replace(etat,'$anc','$nv') where user_id LIKE  
'%$log%'";
$query_exec=mysql_query($query_add) or die(mysql_error()); 
?><script language='JavaScript'>alert('Activation termine')</script><?
$date = date("Y-d-m"); 
$heure = date("H:i"); 
$op=$date.$heure.'Activation du compte de'.$log.'par administrateur'.$logad;
$op .= "\n";
$file = 'log.txt';
$search = file_get_contents($file);
$check = strpos($search, $log);
if ($check === FALSE) {
  $fp = @fopen($file, 'a');
  $write = @fputs($fp, $op);
  @fclose($fp);
}

That would work, assuming $log and $logad have already been defined.

jerdiggity
  • 3,655
  • 1
  • 29
  • 41