Simple request; I need visitors to my site to have a certain cookie to view the website. When user goes to my.site.com/anydirectory/anypage.php they need to be redirected to my.site.com/index.php where they are given a warning and a choice to Walk Away or Continue. If they Continue, a cookie is set and they are take to the originally requested page (and ultimately have access to the whole site, for at least 90 days). If they choose to Walk Away then a different cookie is set and they are redirected to my.site.com/bummer.php, and will continue to be directed to the bummer.php page until 90 days is up or they delete the cookie, whichever comes first.
Here is what I have;
I placed this at the top of all of my pages...
<?php if (!isset($_COOKIE['youwerewarned'])) {
header("Location: /index.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]")
}
?>
...then I placed this at the top of my index.php page...
<?php
// change to your domain name.
$domain = "my.site.com";
// Get the requested page, add it to our domain so we can create an enter link
if (isset($_GET['request'])) {
$request ="<a href='http://$domain" . $_GET['request'] . "'>";
}
// The exit link
{
$leave ="<a href='http://my.site.com/bummer.php'>";
}
// Set a cookie so we are not redirected back here again. You can set how long the cookie is good.
if (!isset($_COOKIE['youwerewarned'])) {
setcookie('youwerewarned','true',time()+6048... . $domain);
}
?>
...then I placed this in the index.php page in the appropriate place...
<?php echo $leave ?>WALK AWAY</a> <?php echo $request ?>CONTINUE</a>
...what am I missing?
Far as I can tell, you're missing a closing/ending semi-colon for:
header("Location: /index.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]")
do:
header("Location: /index.php?url=http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
Then there's this line which I don't know if this => ... .
is part of your actual code or not.
setcookie('youwerewarned','true',time()+6048... . $domain);
which should read as
setcookie("youwerewarned", "true", time()+6048, "/", $domain);
Having error reporting on, would signal
Parse error: syntax error, unexpected '}', expecting ',' or ';' in...(path to file) on line X
for the missing semi-colon.