Link to home
Start Free TrialLog in
Avatar of klykken
klykken

asked on

Set cookie and redirect

I need a very simple cookie (I hope) for a site.

I want visitors to be redirected from the opening page of the website if they have been on that page before. The opening page is a flash movie, and I don't want the visitors to see it every time they enter the site. So when the visitor comes a second time to the site through the opening page, they are automatically redirected to the next page.

Makes sense? :-)
--
klykken
Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

These are your cookie functions:
function setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
    document.cookie = curCookie;
  }
  function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
    } else {begin += 2;}
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {end = dc.length;}
    return unescape(dc.substring(begin + prefix.length, end));
  }

So in the script section in head, write :
now=new Date();
now.setFullYear(now.getFullYear()+1);
setCookie("beenBefore", "yes",now);
if (getCookie("beenBefore")) {
  //redirection code
}
ASKER CERTIFIED SOLUTION
Avatar of Bob Stone
Bob Stone
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of klykken
klykken

ASKER

worked like a dream, thanx :)
--
klykken
worked like a dream, thanx :)
--
XYuan
worked like a dream, thanx :)
--
XYuan
worked like a dream, thanx :)
--
XYuan
worked like a dream, thanx :)
--
XYuan
worked like a dream, thanx :)
--
XYuan
Then gimme points =o)
Avatar of klykken

ASKER

Xyuan should give you x5 as much points as I gave you ;-)
--
klykken
Which, in case he doesn't know, the point amount above (10) is 1/10 the original point value (100).