开发者

How do you create a cookie in PHP that will expire either after a certain amount of time or if the browser closes?

开发者 https://www.devze.com 2023-02-20 17:39 出处:网络
I know how to create a cookie that will expire after a certain amount of time, and I know how to create a cookie that will expire when the browser closes.

I know how to create a cookie that will expire after a certain amount of time, and I know how to create a cookie that will expire when the browser closes. However, I can't seem to find a way to create a cookie capable of doing both. Is it even possible? Would I have to create one of each type开发者_如何学JAVA of cookie and check for the existence of both before considering either to be valid?


Create a cookie which expires when the browser closes. In the PHP session, mark when you issued the cookie. If the cookie is presented to the server (meaning the browser never closed after issuance) check the issuance date (what you earlier stored in PHP session) against the amount of time you wish the cookie to be valid (TTL). If the cookie was issued too long ago, consider it invalid and send the command to delete it.

0

精彩评论

暂无评论...
验证码 换一张
取 消