I want to protect a website from being accessed until a user has agreed to something. The basic idea is that at the top of each page it will check if the cookie exists if not then exit and include a php page that contains the message and two buttons one which will create the cookie and the other simply moving them off the site e.g. google.com
EDIT:
This is what I ended up with:
The warning include would look something like this:
<?php
function pageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
}
else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$pageRedirect = pageURL();
if (
isset($_POST['agree_button']) && ($_POST['agree_button'] == 'I agree')
) {
setcookie('agreed', 'true');
header("Location:$pageRedirect",303);
}
?>
<form action="<?php echo pageURL(); ?>" method="post">
<p>INSERT MESSAGE HERE (User must agree)</p>
<input type="submit" value="I agree" name="agree_button" />
<input type="button" value="I disagree" />
</form>
and the at the top of pages something like this:
<?php
if(!isset($_COOKIE['agreed']) || ($_COOKIE['agreed'] != 'true'))
{
include('warning.php'); exit;
}
?>