1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Cookie Dropping + Redirection...how?

Discussion in 'Programming' started by mberman84, Dec 2, 2008.

  1. #1
    Basically what i wanna do is drop a cookie on each person that comes to my site. If they come to my site again (with the cookie)....they automatically get redirected to another page. How do i do that?

    EDIT: I almost figured it out...but setting a cookie expiration doesnt work...

    this works....

    <?php
    if (isset($_COOKIE['datecookie'])) {
    header("Location: http://www.website.com/");
    exit;
    }
    $Month = time()+60*60*24*30;
    setcookie("datecookie");
    ?>
    Code (markup):
    but this does not...


    <?php
    if (isset($_COOKIE['datecookie'])) {
    header("Location: http://www.website.com/");
    exit;
    }
    $Month = time()+60*60*24*30;
    setcookie("datecookie", "", $Month);
    ?>
    Code (markup):
     
    mberman84, Dec 2, 2008 IP
  2. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #2
    <?php
    if(isset($_COOKIE['datecookie'])) 
    {
    	header("Location: http://www.msn.com/");
    }
    else
    {
    	$month = time()+60*60*24*30;
    	$value = "Hello";
    	setcookie("datecookie",$value, time() + 3600);
    }
    ?>
    Code (markup):
    This will work. Also use cookie editor and tamper data ff addon .

    Its good for php developers.
     
    harrisunderwork, Dec 3, 2008 IP
  3. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yep..that worked...thanks so much.

    follow up question: if i only want to drop the cookie if the person is leaving my site...is that possible? how would i do that? the reason is i dont want them to get redirected if they just refresh the page or click on another page of my site. i only want them to be redirected if they browsed my site and left...and then came back another hour or another day.
     
    mberman84, Dec 3, 2008 IP
  4. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #4
    Good soln would be to store time in datecookie .

    When next u check whether cookie is set , just check whether the date or time diff is greater than u want.

    If it is just redirect them :)

    Reps will be highly appreciated .
     
    harrisunderwork, Dec 3, 2008 IP
  5. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    so basically i give them a 10 minute window or so to navigate the site? that makes sense. how do i give you rep? you definitely deserve it.

    also, how do i do that btw? how do i test to see if the cookie has been set for at least 20 minutes?
     
    mberman84, Dec 3, 2008 IP
  6. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #6
    http://www.weberdev.com/get_example-3307.html

    Here is a time diff function for you.

    Just store current time in cookie.

    And check using above function.

    You can give rep by clicking balance icon on every post on right hand above corner.

    Thanks and regards.
     
    harrisunderwork, Dec 3, 2008 IP
    mberman84 likes this.
  7. mberman84

    mberman84 Peon

    Messages:
    511
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    how do i grab the value from the cookie though? (Sorry im way new to this)
     
    mberman84, Dec 3, 2008 IP
  8. pharmboy

    pharmboy Member

    Messages:
    30
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #8
    The value is stored in $_COOKIE['datecookie']. So when you're setting the cookie, do something like:

    setcookie("datecookie",time(), time() + 3600);
    PHP:
    Then to get the initial time and calculate the difference:

    
    $timedifference = timeDiff($_COOKIE['datecookie'], time());
    PHP:
     
    pharmboy, Dec 3, 2008 IP
  9. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #9
    Solution provided above :)
     
    harrisunderwork, Dec 4, 2008 IP