Forum Moderators: open

Message Too Old, No Replies

javascript cookie redirect

javascript cookie redirect

         

jacquasse

1:42 pm on Mar 16, 2005 (gmt 0)

10+ Year Member



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");

SpaceFrog

3:31 pm on Mar 16, 2005 (gmt 0)

10+ Year Member



if its just a sort of seesion cookies for one visit I would not bother with cookies...
juste set a browser object
with:

navigator.seenit[page]=true

then you would just need to test

if(navigator.seenit[page]){alert('page already visited')}

jacquasse

2:20 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



With the brouwser object how do i redirect a page to another one if it has found the attribute?

SpaceFrog

4:36 pm on Mar 17, 2005 (gmt 0)

10+ Year Member



if(navigator.seenit[page]){window.location.href="newpage.htm")}