简体   繁体   中英

PHP - Call A Function On Cookie Expiry

I was just wondering if there is a pre-made system to call a function when a cookie expires. I was wondering if there was something similar to:

setcookie('cookie', "Value!", time()+300, onexpire{/*Self destruct*/});

If not I can think of a different way to do it

As per knowledge there is no pre-made system for this. Actually its very difficult to achieve your requirement.

But you can create one more cookie that will store your first cookie expire time. And later on use second cookie to check expire time of first one and then call function.

Hope so this way will help your.

Cookies are stored in the client's browser. Browser will not tell the server when cookie expires.

But there are some work-arounds:

  1. Cron-job : Save a copy of cookies in your database, and set a cron-job to deal with them
  2. Ajax : Let client send an ajax request when cookie expires

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM