I am working on a project where it requires to check cookie and tell whether it is 20 minutes old or not. So I have written once code which is like this. This is only javascript code I have pasted.
function checkcookie()
{
var difftime= getcookie();
// further operation comes here
}
var cookieminutes;
function getcookie()
{
var start = document.cookie.indexOf("expires");
var cookiedate;
if(start==-1)
{
cookiedate = new Date();
document.write("Start equal to -1");
document.cookie="expires="+cookiedate+",path=0,domain=0";
cookieminutes= cookiedate.getMinutes();
}
else
{
document.write("Start not equal to -1");
var date = new Date();
var minutes = date.getMinutes();
document.write("The difference is "+minutes);
document.write("<br />Cookie minutes is "+cookieminutes);
return (minutes-cookieminutes);
}
}
In function getcookie the variable cookieminutes is coming as undefined. But as I know since it is a global variable it should have the value.
Can anybody please tell what is the solution for this.?