How To Set a Persistent Cookie

Q

How To Set a Persistent Cookie? - PHP Script Tips - Understanding and Managing Cookies

✍: FYIcenter.com

A

If you want to set a persistent cookie, you can use the setcookie() function with an extra parameter to specify its expiration time. To follow sample script sets 2 persistent cookies to be expired within 7 days:

  setcookie("LoginName","FYICenter");
  setcookie("PreferredColor","Blue");
  setcookie("CouponNumber","07470433",time()+60*60*24*7);
  setcookie("CouponValue","100.00",time()+60*60*24*7);
  print("2 temporary cookies were delivered.\n");
  print("2 consistent cookies were delivered.\n");

2007-04-25, 4671👍, 0💬