Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts

    "Remember my prefrence" cookie.

    Right now on my website I have a splash page for certain browsers.
    For example, if you visit it on IE, you will get a message with a link to enter the site, while Firefox goes directly to the site.

    I am wondering how to create a cookie that I can set to something along the lines of:

    "If a checkbox is checked, the browser will skip the splash page for recurring visits"

    How would I create this? Is it even a cookie? Should I make it in Javascript?

    Thanks.

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Try this

    PHP Code:
    <?php
    //put this at the top of index.php (or whatever the splash screen is called)

    if (isset($_COOKIE['splash'])) {
        
    header("Location: home.php"); //home.php = the site
    }

    ?>
    PHP Code:
    <?php
    //put this at the top of home.php (or whatever the name of the first page is)

    if (isset($_POST['checkbox'])) {
        
    setcookie('splash','true',time()+99999999999);
    }

    ?>

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    224
    Thanks
    1
    Thanked 0 Times in 0 Posts
    well I have it go to "index.php" which then either fowards to .../home/(index.php) or /error/(index.html)

    But how would I make the choice to show the splash page or not?

    Like I said, a check box that says "remember my prefrence"

    do I not put it on the page with the browsercheck javascript?

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    563
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Use this for the splash screen. It's very simplified but you should be able to work it out. If not post a link to your site.

    PHP Code:
    <?php

    if (isset($_COOKIE['splash'])) { 
        
    header("Location: home/index.php");
    }

    //all header information goes here (eg, <html><head> etc)

    ?>
    <form name="form" action="home/index.php" method="post">
    <a href onClick="document.form.submit()"><img src="images/splash.jpg"></a><br><input type="checkbox" name="remember" value="1"></form>
    and use this for the home/index.php

    PHP Code:
    <?php

    if (isset($_POST['remember']) && $_POST['remember'] == "1") { 
        
    setcookie('splash','1',time()+99999999999);
    } elseif (isset(
    $_POST['remember']) && $_POST['remember'] != "1") { 
        
    header("Location: ../error");
    }

    //rest of the page

    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •