...

View Full Version : Two-part cookie script needed



deacon
12-13-2002, 12:26 PM
I submitted a long-winded request last week that got no replies so here is a less verbose version:

First page: need a set cookie script
Second page: need a read cookie + redirect (if the cookie exists).

I tried using an existing script that performs all of those functions on one page but have not been able to rework the script to separate the functions. If anyone wants to look at what I have, it's posted below. Thanks for any help

Existing script:
<script>
<!--

// page to go to if cookie exists
go_to = "otherpage.html";

// number of days cookie lives for
num_days = 60;
function ged(noDays){
var today = new Date();
var expr = new Date(today.getTime() + noDays*24*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");
// -->
</script>

Vladdy
12-13-2002, 01:32 PM
I have a cookie script that is quite simple to use:
http://www.vladdy.net/webdesign/cookies.html
- 3 lines of code to set a cookie, 2 lines to read (you can actually make it 1) plus your redirection line.

whammy
12-13-2002, 11:50 PM
http://www.geocities.com/docwright32nd/persistentcookie.htm

krycek
12-14-2002, 11:05 AM
hehheh, deacon have you ever tried searching :D

...I posted this for someone anly a few days ago

http://www.codingforums.com/showthread.php?s=&threadid=11239

Dunno if it's what you want (vladdy's is shorter) but it works for me ;)

::] krycek [::



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum