Need to have an Age check/age gate before entering site. could someone provide me some help with checking over the code?
Structure:
index.php = age check page - also check to see if the visitor has already been there, but was too young, to kick them to minor.php (hitting the back button from minor.php)
page.php = if 18 and over can enter this page, however if someone inputs the url directly (ie http://www.domain.com/page.php ) it should check to see if the visitor has been to index.php first. If not, then kick the visitor to that page first.
minor.php = this is the page if the person put in a too young age, should send the user to this page. However, the person who put in the page cannot hit the back button to return to index.php to put in an "older" age. Must close the browser completely.
I want to work with Sessions, but the script i have works with cookies. I dont know how to make cookies recognize all of the above for each page.
Code below:
index.php
<?php
if(isset($_POST['checkage'])) {
$day = ctype_digit($_POST['day']) ? $_POST['day'] : '';
$month = ctype_digit($_POST['month']) ? $_POST['month'] : '';
$year = ctype_digit($_POST['year']) ? $_POST['year'] : '';
$birthstamp = mktime(0, 0, 0, $month, $day, $year);
$diff = time() - $birthstamp;
$age_years = floor($diff / 31556926);
if($age_years >= 18) {
setcookie('legal', 'yes', 0, '/', '.'.$_SERVER['SERVER_NAME']);
# cookie expires when the browser closes
/* setcookie('legal', 'yes', time() + 31556926, '/', '.'.$_SERVER['SERVER_NAME']);*/
# The above line sets a cookie called "legal" throughout the entire domain and its value is yes. The cookie will expire next year, if it is not manually deleted.
$url = 'page.php';
} else {
setcookie('legal', 'no',0, '/', '.'.$_SERVER['SERVER_NAME']);
# cookie expires when the browser closes
# setcookie('legal', 'no', time() + 31556926, '/', '.'.$_SERVER['SERVER_NAME']);
# You're not old enough, come back next year!
$url = 'minor.php';
}
header ('Location: ' .$url);
}
?>
page.php and minor.php
<?php
if(isset($_COOKIE['legal'])) { # If the cookie has been set by the script earlier...
$url = ($_COOKIE['legal'] == 'yes') ? '/page.php' : '/minor.php';
header ('Location: ' .$url);
}
?>