I have this:
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 5 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
How to make cookies expire after 10 minutes?
You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the 'expires' attribute to a date and time.
Or you might use mktime(). time()+60*60*24*30 will set the cookie to expire in 30 days. If not set, the cookie will expire at the end of the session (when the browser closes). The path on the server in which the cookie will be available on.
Solution 1 Specifically, time() - 60 is one minute ago, not one minute to come. Try time() + 60 and it will expire in one minute's time ...
var date = new Date();
var m = 10;
date.setTime(date.getTime() + (m * 60 * 1000));
$.cookie("cookie", "value", { expires: date });
Alternatively you could use a function:
function ExpireCookie(minutes) {
var date = new Date();
var m = minutes;
date.setTime(date.getTime() + (m * 60 * 1000));
$.cookie("cookie", "value", { expires: date });
}
Then do ExpireCookie(10);
10 minutes is 10 * 60 * 1000 milliseconds.
var date = new Date();
date.setTime(date.getTime() + (10 * 60 * 1000));
$.cookie("example", "foo", { expires: date });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With