This is a follow-up question from here.
The code is working great, it randoms the link to a blog post. The downside is that I may fall into the same post twice or too often.
header("Location: ".$posts[array_rand ($posts)][1]);
I need it to not fall on the same post more than once every 20 minutes, if runs out of posts then say: “Out of options. Come back in 20 minutes.”. I tried doing it with cookies like so:
$rlink = $posts[array_rand ($posts)][1];
setcookie("rlink", "$rlink", time()+1200);
if ($rlink == $_COOKIE["rlink"]) {
header('Location: http://localhost/randommyblog.php');
} else
{
header("Location: ".$rlink);
}
It might be obvious that the problem here is that I’m replacing the cookie “rlink” every time, rendering the previous one useless.
Little help, please?
Try something like this, worked when I tested it as is: