i just need to set this function to expire in one month, can someone tell me how to do it?
function _saveUserPreference() {
// Set the cookie expiry to one year after today.
var expiryDate = new Date();
expiryDate.setFullYear(expiryDate.getFullYear() + 1);
document.cookie = cookieName + '=y; expires=' + expiryDate.toGMTString();
}
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.
Just set the expires parameter to a past date: document. cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; You should define the cookie path to ensure that you delete the right cookie.
php setcookie("TestName", "Test Value", time()+3600 * 24 * 365); ?> >> Here 'TestName' is name of cookie. >> "Test Value" is value to store. >> time()+3600 * 24 * 365 - will set cookie time till 1 year.
Cookies with an expiration date in the past will be removed from the browser. To remove a cookie, you must set it's set its expiration date in the past. This will signal to the browser that the cookie should be removed. For cleanliness, it's also a good idea to set its value to an empty string.
You need add one month to the expiryDate
var:
var expiryDate = new Date();
expiryDate.setMonth(expiryDate.getMonth() + 1);
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