PHP expert |
|
<?php
if(isset($_COOKIE['daysong']))
{
echo $_COOKIE['daysong'];
} else {
$daysong = $randomnr[rand(1,4)];
echo $daysong;
$now = time(); // huidige timestamp
$tomorrow = $now + 24*60*60; // huidige tijd morgen (+24 uur)
$tomorrow = mktime(0, 0, 0, date('n', $tomorrow), date('j', $tomorrow), date('Y', $tomorrow)); // timestamp morgen om 00:00:00
$timeleft = $tomorrow - $now; // tijd te gaan tot morgen om 00:00:00
setcookie("daysong", $daysong, time() + $timeleft, "/"); // cookie setten met time to live => time() + $timeleft
}
<?php if(isset($_COOKIE['daysong'])) { echo $_COOKIE['daysong']; } else { $daysong = $randomnr[rand(1,4)]; $now = time(); // huidige timestamp $tomorrow = $now + 24*60*60; // huidige tijd morgen (+24 uur) $tomorrow = mktime(0, 0, 0, date('n', $tomorrow), date('j', $tomorrow), date('Y', $tomorrow)); // timestamp morgen om 00:00:00 $timeleft = $tomorrow - $now; // tijd te gaan tot morgen om 00:00:00 setcookie("daysong", $daysong, time() + $timeleft, "/"); // cookie setten met time to live => time() + $timeleft }
Enjoy. |