Home >Web Front-end >HTML Tutorial >When accessing the page via WeChat, it refreshes twice for no apparent reason. There is no problem with Firefox, Google, and IE_html/css_WEB-ITnose
When doing the WeChat scratch card activity, there is a limit on the number of times a user can scratch. Yesterday everything was normal, so I changed some things. When I opened it again today, the number of scratches was 1 for the first time and 1 for the second time. It is 3, and the third time is 5. It feels like the page has been refreshed twice. After checking the front-end and back-end code, I found some bugs and modified them easily. In fact, they were not the real cause of the problem. I had no choice but to write a counter myself to count the number of visits to the current page. I found that in WeChat, it jumps directly from 1 to 3, and then to 5. Other PC browsers have no problem at all. From the background code, check the foreground html. It is like a breakpoint. First clear the php code and test whether it is skipped when the html is displayed. Then clear the html code and test whether it is skipped when running the background code. Finally detected. . . . , yes, it is because I wrote a link but did not copy the href, which resulted in repeated refreshes. .
Attachment: php counter code:
class Counter{
//$five, $four and other variables represent the number of zeros, placed in front of the number Constitute a 6-bit public function counterFunction()
🎜> $four = "0000";
$three = " 000";
$two = "00";
$one = "0";
$counter = "C:/error/record.dat"; dat format
if(!file_exists($counter)) //Determine whether the file exists (the file does not exist)
{
$counter = fopen($counter,"w");
fputs( $ Countr, "0"); // Write the file
FClose ($ counter);
}
Else
{
$ fp = Fopen ($ counter, "r");
$num = fgets($fp,"1024"); //If the file exists, read the file and add 1
$num = $num 1;
if($num < 10)
print "$five"."$num";
elseif($num < 100)
print "$four"."$num";
elseif($num < 1000)
print "$three"."$num";
elseif($num < 10000)
print "$two"."$num";
elseif($num < 100000)
print "$one"."$num";
else
print "$num";
}
$fp = fopen($counter,"w");
fputs($fp,"$num");
fclose($fp);
}
}
?>