PHP Header Redirect Based on Cookie Insertion Date?

superaff1984

Senior Member
Premium Member
Joined
Jun 16, 2010
Messages
992
Reaction score
131
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?
 
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
}
 
Back
Top