简体   繁体   中英

PHP- How to renew cookie expiration date?

I am setting a cookie that is good for 3 days:

setcookie('whatever', 'value', time() + (86400 * 3), "/");

If and when the user does something else at a later point in time, I want to renew this cookie's expiration date. I don't need to update it's value or anything- just renew the 3 days expiration date.

How is this most simply done?

From what I understand, I have two options:

1: Redeclaring the value of the cookie

Like:

$value = $_COOKIE['whatever'];
$_COOKIE['whatever'] = $value;
  1. Re-setting the cookie altogether

Like:

$value = $_COOKIE['whatever'];
setcookie('whatever', $value, time() + (86400 * 3), "/");

How would you go about just re-initiating the expiration date of a cookie?

2 is the right way to do it.

$value = $_COOKIE['whatever'];
setcookie('whatever', $value, time() + (86400 * 3), "/");

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