Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2003

    I Need A Cookie...Can't Figure It Out

    Hey All,

    I've been trying to create a cookie that will show a "splash" page to a visitor only on their first time visiting the website, but I can't figure out how to do it.

    Is there a simple way to do this, or can someone show me an example cookie and code....i'm totally baffled.

    - Sean

  2. #2
    Join Date
    Jun 2004
    Woodinville Washington US
    upon login, have it create a cookie that says 'firstlogin'

    setcookie("firstlogin", "1", time()+3600);
    Then when loading the page, do this:

          if($_COOKIE['firstlogin'] == 1){ 
                       #DO YOUR ACTION HERE
                       #Once the action is complete, change the value in the cookie, or remove it
                       setcookie('firstlogin', '0', time()-300);
            } else {
                       ITS NOT THEIR FIRST LOGIN - some action here
       } else {
    THE COOKIE IS NOT SET - action here
    Hope that helps.

  3. #3
    yeh something like that or this:
    $cookie = $_COOKIE[visitedbefore];
    if($cookie==FALSE) {
    setCookie("visitedbefore", "yes");
    echo "<html>\n<body>\n<p>You are new here welcome <a href=site.php>enter site</a>\n</body>\n</html>";
    if($cookie==TRUE) {
    echo "<html>\n<body onLoad=window.location=window.location>\n<p>Welcome back redirecting to <a href=site.php>site.php</a>\n</body>\n</html>";
    but cookies r unrealiable as they might be switched off or not be supported i suggest this as an alternative way, its called I.P. tracking it checks if that person is a first time visitor it requires mysql for this i'll just guess you know my sql
    //connect to database
    $link = mysql_connect("localhost", "user", "pass");
    mysql_select_db("IPlogger", $link);
    //i.p. track
    $ipquery = mysql_query("SELECT timeanddate, visitcount FROM iplog WHERE ip ='$REMOTE_ADDR'", $link);
    $ipresult = mysql_fetch_array($ipquery);
    if($ipresult == FALSE) {
    echo "Hello there, you seem to be a new visitor $REMOTE_ADDR welcome to my site <a href=site.php>enter</a>";
    else {
    echo "<html>\n<body>\n<p>Welcome back $REMOTE_ADDR dude, its your $ipquery[visitcount] time visiting, you were last on at:$ipquery[dateandtime]</p>\n</body>\n</html>";
    $newcount = $ipquery[visitcount]+1;
    $newtimeanddate = date("j/f/Y at h:i A");
    mysql_query("UPDATE iplog SET visitcount='$newcount', timeanddate='$newtimeanddate' WHERE ip='$REMOTE_ADDR'", $link);

  4. #4
    I would give you a few links to help you out, but it won't let me post URL's. So I'll do my best.

    Always check

  5. #5
    but she already has 2 solutions from me and hasnt checked back yet

  6. #6
    Join Date
    Jul 2004
    Scotland, UK
    Originally posted by maddudemike
    but she already has 2 solutions from me and hasnt checked back yet
    With the name "Sean" in the sig, I'm going to guess that "she" is a he. I'm sure he'll check back shortly
    Scott - My Spiel

Posting Permissions

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