php - incrementing counter in multiple text file -


i'm trying increment counter in multiple text file when user visit page, code i'm working not working below code

$files = glob("counters/visit/*.txt");   foreach($files $file) {     $content = file_get_contents($file);       if(!isset($_session['hasvisited'])){       $_session['hasvisited']="yes";       $content++;       $f = fopen($files, "w");       fwrite($f, $content);       fclose($f);     } } 

first make sure $contentis integer doing following :

$content = intval(file_get_contents($file)); 

then you're using :

$f = fopen($files, "w");

instead of :

$f = fopen($file, "w");

fopen can't accept array parameter

also mentioned @alanlittle, if want files incremented, should think moment set $_session['hasvisited']="yes"; , put @ end of loop.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -