Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirection using PHP and Javascript and setting cookies
    primarykey
    data
    text
    <p>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.</p> <ol> <li>if the user has never been to the site before, redirect to splash page.</li> <li>if user has been to the site before and did not want to see the splash don't redirect.</li> <li>if user likes splash and wants to see upon new session, show splash page.</li> </ol> <p>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.</p> <p><strong>index.php</strong></p> <pre><code>&lt;?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 == '' &amp;&amp; $cookie_visit == '' &amp;&amp; $cookie_visit_now == '') { /* echo "&lt;script type = text/javascript&gt;"; echo "window.location = 'http://chrisrjones.com/splash.php'"; echo "&lt;/script&gt;"; */ header('Location: splash.php'); } if ( $cookie_splash == 'false' &amp;&amp; $cookie_visit_now == 'true') { break; } if ( $cookie_splash == 'true' &amp;&amp; $cookie_visit_now == 'false') { /* echo "&lt;script type = text/javascript&gt;"; echo "window.location = 'http://chrisrjones.com/splash.php'"; echo "&lt;/script&gt;"; */ header('Location: splash.php'); } if ( $cookie_splash == 'true' &amp;&amp; $cookie_visit == 'true' &amp;&amp; $cookie_visit_now == "false") { /* echo "&lt;script type = text/javascript&gt;"; echo "window.location = 'http://chrisrjones.com/splash.php'"; echo "&lt;/script&gt;"; */ header('Location: splash.php'); } if ($cookie_splash == 'true' &amp;&amp; $cookie_visit == 'true' &amp;&amp; $cookie_visit_now == 'true') { break; } } while (0); ?&gt; </code></pre> <p><strong>splash.php</strong></p> <pre><code>&lt;p&gt; &lt;form name="tosplashornottosplash" action="scripts/splash-process.php" method="post" onSubmit="return valForm()"&gt; Splash pages are stupid. &lt;input type="radio" name="splash" id="splash_false" value="false" /&gt; No &lt;input type="radio" name="splash" id="splash_true" value="true" /&gt; Yes &lt;input type="submit" name="splashSubmit" onClick="return valForm(tosplashornottosplash)" value="Enter" /&gt; &lt;/form&gt; &lt;/p&gt; </code></pre> <p><strong>splash-process.php</strong></p> <pre><code> &lt;?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 "&lt;script type = text/javascript&gt;"; echo "window.location = 'http://chrisrjones.com/index.php'"; echo "&lt;/script&gt;"; ?&gt; </code></pre> <p>Go to chrisrjones.com to see what I'm talking about.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload