This works with a full date, it includes a sweet form with select fields and hey, it works. 
Look at the comments, they should tell you where you should replace things.
This is the function.
PHP Code:
function isOldEnough()
{
if (isset($_POST['send'])) {
if (checkdate($_POST['bd_month'], $_POST['bd_day'], $_POST['bd_year'])) {
if (($timestamp = mktime(0, 0, 0, $_POST['bd_month'], $_POST['bd_day'], $_POST['bd_year'])) == -1) {
die('Wrong date format'); // Replace this with your own error message
} else {
$diff = time() - $timestamp;
if ($diff <= 0) {
die("Hooah! How's the future?" ); // Replace this with your own error message
} else {
$ysec = 60 * 60 * 24 * 365;
$years = floor($diff / $ysec);
if ($years >= 13) {
$expire = 60*60*24;
$days = 30;
setcookie('not_old_enough', 0, $expire*$days + time());
header('Location: '.$_SERVER['PHP_SELF']);
exit;
} else {
$expire = 60*60*24;
$days = 30;
setcookie('not_old_enough', 1, $expire*$days + time());
header('Location: '.$_SERVER['PHP_SELF']);
exit;
}
}
}
} else {
die('Invalid date'); // Replace this with your own error message
}
} else {
if (isset($_COOKIE['not_old_enough'])) {
return !(bool)$_COOKIE['not_old_enough'];
} else {
echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">';
echo '<input type="text" name="bd_day" maxlenght="2" size="2" /> ';
echo '<select name="bd_month" size="1">';
for ($i = 1; $i <= 12; $i++) {
$time = mktime(0, 0, 0, $i);
$date = date('F', $time);
echo '<option value="'.$i.'">'.$date.'</option>';
}
echo '</select> ';
echo '<select name="bd_year" size="1">';
for ($i = 1970; $i <= date('Y'); $i++) {
echo '<option>'.$i.'</option>';
}
echo '</select> ';
echo '<input type="submit" name="send" value="Enter" />';
echo '</form>';
exit;
}
}
}
Now, in every file where you have to be >= 13 you do this
PHP Code:
if (isOldEnough()) {
// Your content
echo 'Hooray! You\'re old enough!';
} else {
// Not old enough message
echo 'Sorry mate, wait till you\'re 13.';
}
Bookmarks