here is my code
echo ("<br/>");
if ($APIkbpersec < 30) {
global $SpeedTest;
echo ("Slow speed");
$SpeedTest--;
}
if ($APIkbpersec > 30) {
global $SpeedTest;
echo ("High speed");
$SpeedTest++;
}
echo $SpeedTest;
the page this code is in gets reloaded every second with AJAX and the $APIkbpersec changes between 40 and 0.
I basically want to have a variable ($SpeedTest) increase or decrese depending on what $APIkbpersec is.
- if
$APIkbpersecis less than 30, I want$SpeedTestto decrease by 1 every refresh to a minimum of 0. - if
$APIkbpersecis greaterthan 30, I want$SpeedTestto increase from by 1 every refresh to a maximum of 10.
the problem is I dont know what the porblem is….Im currently trying to write $SpeedTest to a txt file so I can read it in every refresh to do the maths on it every refresh without it being reset in PHP
any help would be appreciated
It’s being reset because the HTTP request is stateless. Each AJAX call is an isolated event to a PHP script. To make the variable persist, it has to be stored in
$_SESSION.You have not shown the code you’re using to write it to a text file, but unless you need it to persist beyond a user session, that’s the wrong approach. You’re better served using
$_SESSION. If you do need long-term persistence, you should use a database instead.