Sunday, 22 November 2015

XML : Variable not increasing by 1

I am trying to increase value of variable by one it increases but while saving the variable is increase by 2. I don't know what to do. I've tried both file_put_contents() but nothing works. I've tried this code on XMAPP running on PHP 5.6 as main developing environment but when I use same script on IIS 8 with PHP 5.5 it worked fine. Here's the code.

  <textarea>  <?php $date=date('Y-m-d');      $head="<?xml version='1.0' encoding='utf-8'?><stat><pageview>0</pageview><visitor>0</visitor></stat>";      if(!file_exists("admin/stats/$date.xml")){      file_put_contents("admin/stats/$date.xml","$head");       }      $data=simplexml_load_file("admin/stats/$date.xml");      $pageview=$data->pageview;      $uniq=$data->visitor;      //echo $pageview;      $uniq=(int)$uniq;      $pageview=(int)$pageview;          echo"$pageview/$uniq";      //var_dump($uniq);      //var_dump($pageview);     $file=fopen("admin/stats/$date.xml","w");      fwrite($file,"<?xml version='1.0' encoding='utf-8'?><stat><pageview>".++$pageview."</pageview><visitor>".++$uniq."</visitor></stat>");      fclose($file);  ?>  </textarea>    

No comments:

Post a Comment