PHP Question About Cookies

superaff1984

Senior Member
Premium Member
Joined
Jun 16, 2010
Messages
991
Reaction score
131
Am I able to redirect visitors based on the cookie date. Say for example, a cookie inserted into your browser today. You come back to visit the site 2 weeks later. I can check when the cookie was inserted, if it was inserted 2 weeks ago (from today) it would redirect the user into another URL?
 
Aaah...

I think I may have an idea about this. When the visitor basically arrives on your site, the cookie is placed in their browser. It also includes a timestamp!

Each time they return, the script would run on your website and read the cookies and retrieve the timestamp, also calculate the difference between the current date and the timestamp from the cookie.

You've decided on a threshold – in your case, 2 weeks. This is how long the cookie can exist before triggering the redirect:
  • If Difference is Less Than 2 Weeks: The visitor is allowed to continue seeing the site as usual.
  • If Difference is 2 Weeks or More: The script automatically redirects the visitor to a different URL of your choice.
You can basically do it with a PHP script and manipulate this and how the site behaves, of course.
 
Assign the users timestamp as a cookie variable setcookie and then retrieve it with $_cookie["timestamp"], where the timestamp is made from the time()

https://www.w3schools.com/php/func_network_setcookie.asp
 
Back
Top