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

PHP Header Redirect Based on Cookie Insertion Date?

Discussion in 'General Programming Chat' started by superaff1984, Feb 23, 2012.

  1. superaff1984

    superaff1984 Power Member

    Joined:
    Jun 16, 2010
    Messages:
    619
    Likes Received:
    20
    Location:
    West Los Angeles, CA
    How can I redirect someone based on the cookie date of insertion. We are setting cookies in our visitors browsers. If that cookie is older then 7 days I want to redirect them to another page. If the cookie is not older then 7 days they will continue going to the current page they visited?
     
  2. lanbo

    lanbo Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 23, 2009
    Messages:
    3,433
    Likes Received:
    595
    Home Page:
    Set your cookie:
    setcookie("TestCookie", $value, time()+604800);//1 week old cookie

    Check if cookie has expired:
    if(!isset($_COOKIE['TestCookie'])){
    header("location: /page.php");//older than 1 week
    }