I want to redirect to a splash page for first time visitors to the site using cookies to remember that they came. This is easy, however, for people with cookies disabled, I never want to redirect them to the splash page.
The problem I'm running into is that when I set the cookie, PHP won't see it until I reload the page. This means first time visitors are not redirected unless they visit the home page twice or reload the page.
Here's what I have that works but requires a reload:
setcookie("test",'1',time() + 3600,'/');
if(isset($_COOKIE['test'])){
if(isset($_COOKIE['bfc_splash'])){}else{
header("Location: splash/");
}
}
I tried this, but it seems SESSION info is stored in a cookie, because it just infinitely redirects:
if(isset($_COOKIE['test'])){
if(isset($_COOKIE['bfc_splash'])){}else{
header("Location: splash/");
}
}elseif(!isset($_COOKIE['test']) && !isset($_SESSION['cookies'])){
setcookie("test",'1',time() + 3600,'/');
$_SESSION['cookies'] = '1';
header("Location: index.php");
}
I would prefer not to use javascript to check for cookies, since someone who disables cookies is likely to also disable javascript. Any insight or links to solutions would be much appreciated. I haven't found much so far.