Hi,
Can somebody please tell me what’s wrong with this code?
thebest.txt starts with 0!!!0!!!0!!!0!!! and then should grow with each new player. The get data comes through ajax and arrives ok, i’ve checked. but in the end the ‘thebest.txt’ file is empty -> nothing at all!
Thanks
<?php
$thename = $_GET[‘thename’];
$theschool = $
$thegrade = $_GET[‘thegrade’];
$thesec = $
$thelinenr = $_GET[‘thelinenr’];
$file = ‘thebest.txt’;
$fh = fopen($file, ‘r’) or die(‘Could not open file!’);
$data = fread($fh, filesize($file)) or die(‘Could not read file!’);
fclose($fh);
$signPos=0;
if ($thelinenr>0){
for($counter=0;$counter<$thelinenr+1;$counter++){
$signPos=strpos($data,”!!!”,$signPos+1);
}
}
$cleanedstr2=substr_replace($data,””,0,$signPos);
$temp=$thename.”!!!”. $theschool.”!!!”. $thesec.”!!!”. $thegrade.”!!!”;
$cleanedstr1=substr_replace($data,””,-strlen($data)+$signPos,strlen($data)-$signPos);
$fh = fopen($file, ‘w’) or die(‘Could not open file!’);
fwrite($fh,$cleanedstr1) or die(‘Could not write file!’);
fclose($fh);
$fh = fopen($file, ‘a’) or die(‘Could not open file!’);
fwrite($fh,$temp) or die(‘Could not write file!’);
fwrite($fh,$cleanedstr2) or die(‘Could not write file!’);
fclose($fh);
?>