Alright, I’ll try and keep this simple and sweet. I am working on my wesbsite, and it currently loads a splash page when the user first loads the site. That is the behavior I want.
- if the user has never been to the site before, redirect to splash page.
- if user has been to the site before and did not want to see the splash don’t redirect.
- if user likes splash and wants to see upon new session, show splash page.
those basically the scenarios i am working with, can’t really think of any more, been trying to hack something out for the past couple of hours with no luck.
index.php
<?php
setcookie("visit", "true", mktime (0, 0, 0, 12, 31, 2014), "/"); // delete cookie on 31DEC14
$cookie_splash = $_COOKIE['splash'];
$cookie_visit = $_COOKIE['visit'];
$cookie_visit_now = $_COOKIE['visit_now'];
do {
if ($cookie_splash == '' && $cookie_visit == '' && $cookie_visit_now == '') {
/*
echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/splash.php'";
echo "</script>";
*/
header('Location: splash.php');
}
if ( $cookie_splash == 'false' && $cookie_visit_now == 'true') {
break;
}
if ( $cookie_splash == 'true' && $cookie_visit_now == 'false') {
/*
echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/splash.php'";
echo "</script>";
*/
header('Location: splash.php');
}
if ( $cookie_splash == 'true' && $cookie_visit == 'true' && $cookie_visit_now == "false") {
/*
echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/splash.php'";
echo "</script>";
*/
header('Location: splash.php');
}
if ($cookie_splash == 'true' && $cookie_visit == 'true' && $cookie_visit_now == 'true') {
break;
}
}
while (0);
?>
splash.php
<p>
<form name="tosplashornottosplash" action="scripts/splash-process.php" method="post" onSubmit="return valForm()">
Splash pages are stupid.
<input type="radio" name="splash" id="splash_false" value="false" /> No
<input type="radio" name="splash" id="splash_true" value="true" /> Yes
<input type="submit" name="splashSubmit" onClick="return valForm(tosplashornottosplash)" value="Enter" />
</form>
</p>
splash-process.php
<?php
setcookie("visit", "true", mktime (0, 0, 0, 12, 31, 2014), "/"); // delete cookie on 31DEC14
setcookie("visit_now", "true", NULL, '/'); // cookie should expire / delete at end of session.
$splashvar = $_POST["splash"];
if ( $splashvar == "false" ) {
// create cookie - splash 1
setcookie("splash", "true", time()+3600, '/'); // expires in one hour
}
else {
// create cookie - splash 0
setcookie("splash", "false", time()+3600, '/'); // expires in one hour
}
echo "<script type = text/javascript>";
echo "window.location = 'http://chrisrjones.com/index.php'";
echo "</script>";
?>
Go to chrisrjones.com to see what I’m talking about.
Alright, so I think the problem wasn’t with my code, but rather understanding how browsers behave. If I go to the site (chrisrjones.com) as of right now in FF 18.0.2 and select “No” on splash pages are stupid, then I can enter the site once I click enter.
However if I leave the tab open, and have FF set to leave tabs open on restart (whatever it’s called you know what I mean), and quit FF, then relaunch it the session cookies never expire. So when I refresh the page thus the splash page isn’t loaded. However, if I close the tab then quit the browser then reload the page, the splash page is loaded. (Which is what I want).
Chrome on the other hand appears to not delete session cookie’s once the browser is closed, so that’s why I was having such difficulty with Chrome.
I now have a better understanding as why things are behaving the way they are, and realize it wasn’t all my poor coding practice.