简体   繁体   中英

Persistent cookie vs Temporary cookie

I am new to php , I came across cookie and persistent cookie and i understand the difference between them.My question is that how can i make cookie persistent or temporary.I found only one syntax for cookies

 <?php
setcookie("user", "Alex Porter", time()+3600);
?>

Thanks

Phisically speaking, there is only one kind of cookie. You can make it persistent by choosing a large enough expiration time. If the expiration time is set to 0, the cookie will last only until your page is opened in the browser.

Your example cookie is persistent, it expires in one hour.

Here is a link with a short explanation.

Most likely you can hardly access the phisical cookie on your hard disk, because borwsers store them in their internal logic. For example Firefox store cookies in a local SQLite database file in the browser's profile folder.

When creating a cookie, 3rd argument ( time()+3600 in your example) specifies cookie's expiry date.

time()+3600 means now+3600 seconds, which is 1 hour in the future. Time() function returns current time (unix time) in seconds.

There is no such thing as a really permanent cookie, more like expiring far in the future cookie.

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