freddddyyyyy
freddddyyyyy

Reputation: 21

add 30 minutes to $when so that after 30 minutes people can't view page anymore in PHP

So after 30 minutes the result page is not visible anymore, I used strtotime. My code will make it clear, what do I need to put at the { ???? }

<?php
    $when = strtotime('2012-10-23 13:39:00');
    if ($when < time()){
        ?> <a href="result.php?">Bekijk de resultaten!</a>
        <?php echo "update every 2 min";
       }
     elseif ( ???? )
     { echo "overtime";}
     else
    {echo "De wedstrijd begint om 13:39 vandaag!";}

?>

Thanks :)

Upvotes: 0

Views: 219

Answers (3)

Kenneth
Kenneth

Reputation: 589

If you have the individual components of the date you could also use mktime and add 30 to the minutes value and php would parse it exactly they way you want. The following two lines would return the exact same values:

echo date("n/j/Y H:i:s", mktime(13, 69, 00, 10, 23, 2012));
echo date("n/j/Y H:i:s", mktime(14, 9, 00, 10, 23, 2012));

If all you have is the string value then the previously mentioned approaches would work well.

Upvotes: 0

macino
macino

Reputation: 457

I assume the main part with the link should be visible at 13:39 to + 30 minutes, so I also corrected the if part. The + 30 minutes is in strtotime quite sweet. You just type after the time string +30 minutes.

<?php
  $time = '2012-10-23 13:39:00';
  $startTime = strtotime($time);
  $stopTime = strtotime($time + ' +30 minutes'); 
  if ($startTime > time() && $stopTime < time()) {
    echo "<a href=\"result.php?\">Bekijk de resultaten!</a>";
    echo "update every 2 min";
  }
  elseif ( $stopTime > time() ) {
    echo "overtime";
  } else {
    echo "De wedstrijd begint om 13:39 vandaag!";
  }
?> 

Upvotes: 0

Alex
Alex

Reputation: 7374

Where you have your question marks:

elseif (($when + 1800) > time())

1800 is 30 times 60 seconds (30 minutes in seconds)

Upvotes: 1

Related Questions