1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Redirect unique visitors

Discussion in 'HTML & JavaScript' started by total.load, Oct 12, 2012.

  1. total.load

    total.load Newbie

    Joined:
    Jan 24, 2012
    Messages:
    22
    Likes Received:
    2
    I've found this JS code, that set cookie:


    What I must modify, so the cookie 'll expire every 24h? And how I must save it(as a index) ?
     
  2. SonicSam

    SonicSam Registered Member

    Joined:
    Aug 21, 2012
    Messages:
    57
    Likes Received:
    5
    Location:
    X
    Replace '999' with '1', it seems the function createCookie's 3rd parameter is "days" so 1 will be 24 hours.

    As for the second part of your question, I don't get what you mean.
     
  3. total.load

    total.load Newbie

    Joined:
    Jan 24, 2012
    Messages:
    22
    Likes Received:
    2
    Forget about my first post.
    I've managed to build this:
    PHP:
       <?php
        
    //Checks if there is a cookie
        
    if(isset($_COOKIE["cookiename"])) //if cookie is set
        
    {
              
    header("Location: redirectDOTcom"); //redirect to
        
    }
        else
       
        
    setcookie"cookiename""something"time()+3600*24"""domainname" ); //set cookie name, variable and expiring time
        
    {
           
    header("Location: redirectuniquehit "); //redirect the unique view
        
    }
         
        
    ?>
    The cookie is successful set, and after setting the cookie it redirect the unique visit. The problem is, when I go to the web-page 2nd time, it's redirecting me as a unique view, even if the cookie is set.
    What I have to edit, to make it working?
     
  4. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    misplaced {
    PHP:
        <?php
        
    //Checks if there is a cookie
        
    if(isset($_COOKIE["cookiename"])) //if cookie is set
        
    {
              
    header("Location: redirectDOTcom"); //redirect to
        
    }
        else
        {
           
    setcookie"cookiename""something"time()+3600*24"""domainname" ); //set cookie name, variable and expiring time    
           
    header("Location: redirectuniquehit "); //redirect the unique view
        
    }
         
        
    ?>
     
    • Thanks Thanks x 1
  5. total.load

    total.load Newbie

    Joined:
    Jan 24, 2012
    Messages:
    22
    Likes Received:
    2
    It's workin' :)