Lewis Day Lewis Day -5 years ago 92
PHP Question

If timestamp wasn't updated within 10 seconds

Basically the

is updated every 10 seconds. Now I have one If statement which states if the
was updated within the 10 second gap then to echo
within the ten seconds
What I am trying to achieve is to also echo out
not within the ten seconds
. I thought that I could achieve this by changing the
greater than
to a
less than
however this did not work. Any suggestions?


$usr_timestamp = $usr['timestamp'];
$timeout = time(-10);

if ('$usr_timestamp' > '$timeout'){
echo 'within the ten seconds';

What I'm trying to do is set a condition for if the
hasn't been updated within the last 10 seconds.

This is what I thought would work;

if ($usr_timestamp < '$timeout'){
echo 'not within the ten seconds.';

Answer Source

You are basically checking 2 strings if they are smaller than the other (they would be cast to int and then would both be 0), varables do not get evalutated inside singe quotation marks so you need to use double quotation marks or none of them.

if ($usr_timestamp > $timeout){
   echo 'within the ten seconds';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download