Forum Moderators: mack

Message Too Old, No Replies

code to set cookies to a flash player presentatioon

         

presson

2:49 am on Sep 1, 2003 (gmt 0)



I need a code to set cookies so that when a visitor visits the third or fourth time or any time after that they won't have to go through the introductoory flash presentation. I know that could click on skip, but I want it to work in a way that it goes straight to the homepage after the third visit. Thanks.

JamesR

8:03 pm on Sep 3, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



*bump*

calling all cookie experts

RonPK

3:46 pm on Sep 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The best way to achieve this (imho) would be to have the server set the cookie and update it each time the visitor comes by. But I don't know whether you're able to use some server side scripting language.

The second best way, again IMHO, would be to use JavaScript in the page that contains the movie. Try this:


<script type="text/javascript">
var myCookies = document.cookie;
var p = myCookies.indexOf("seenthis=");
var seenthis = (p!= -1)? myCookies.substring(p + 9, p + 10) : 0;
if (seenthis > 3 ) {
location.href = "pasttheintro.html";
} else {
var farfuture = new Date();
farfuture.setFullYear(farfuture.getFullYear() + 10);
seenthis++;
document.cookie = "seenthis=" + seenthis + "; expires=" + farfuture.toGMTString();
}
</script>

Setting and reading cookies is not that difficult. Pretty basic JavaScript - next time, try doing it yourself ;)

Off course this won't work in browsers where JavaScript is disabled. That's why I'd prefer a server side solution. Neither will work if folks are blocking cookies, though.