Lewis Day Lewis Day - 5 months ago 14
PHP Question

If timestamp wasn't updated within 10 seconds

Basically the

$usr_timestamp
is updated every 10 seconds. Now I have one If statement which states if the
$usr_timestamp
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?

Example

$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
$usr_timestamp
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

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';
}