In the same folder, i have a login page X which when successfully logged goes to page Y.
I'm trying to tweak a javascript which writes a cookie when a user reaches the page Y so that if he goes back to page X, the cookie is read and automatically redirects him to page Y (and he doesn't need to login again).
I have tried with the below code put in the head of both files but it writes the cookie in page x.
Consequence: even if a user does not succesfully log in, if he goes to, say page Z, and comes back to page X he is redirected to Y!
Does anyone know how to tweak the below code? What should i put in page X and Y for it to function properly?!
//COOKIE
// page to go to if cookie exists
go_to = "calendar/index.php";
// number of days cookie lives for
num_days = 1;
function ged(noDays){
var today = new Date();
var expr = new Date(today.getTime() + noDays*60*60*1000);
return expr.toGMTString();
}
function readCookie(cookieName){
var start = document.cookie.indexOf(cookieName);
if (start == -1){
document.cookie = "seenit=yes; expires=" + ged(num_days);
} else {
window.location = go_to;
}
}
readCookie("seenit");