PDA

View Full Version : Cookie redirect



lou smorrels
01-13-2006, 08:37 AM
Help!

Essentially what I am after is a cookie that on first visit opens page x.htm - writes a value, say 1, back to the cookie.

When the user next visits, the cookie reads the value 1 and redirects to page x2.htm and writes the value 2, next visit to x3.htm and so on to whatever value and then after say 10 different pages returns to page x.htm !

I am aware that this will not trap users that override normal cookie handling but I am prepared to miss a few users.

At the moment I am using JavaScript to randomize the pages but this is a very inelegant way of getting the job done!

Thing is I have never written a cookie :o - does anyone out there have one that will do the trick?


<body bgcolor="#C0C0C0" bottommargin="0" onload="go()" bgcolor="#C0C0C0">

<SCRIPT LANGUAGE="JavaScript">
var urlarray= new Array(
"index1.htm",
"index2.htm",
"index3.htm",
"index4.htm",
"index5.htm",
"index6.htm",
"index7.htm",
"index8.htm",
"index9.htm",
"index10.htm",
"index11.htm",
"index12.htm",
"index13.htm",
"index14.htm",
"index15.htm",
"index16.htm",
"index17.htm",
"index18.htm",
"index19.htm",
"index20.htm",
"index21.htm",
"index22.htm",
"index23.htm",
"index24.htm",
"index25.htm",
"index26.htm");

randomno=Math.floor((Math.random()*urlarray.length));

urlran=urlarray[randomno]

</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
function go(){
var url =urlran
var target="_self"
window.open(url,target)
}
</SCRIPT>

jscheuer1
01-13-2006, 09:54 AM
Cookies (http://www.quirksmode.org/js/cookies.html) at Quirksmode is a very good unit for this. A one page primer, if you will, with example code that will do all the hard parts for you.

lou smorrels
01-13-2006, 10:03 AM
Many thanks - I will have a look!