Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

checking if cookie exists

I set a cookie with Perl.  Now on each page, I'm going to include a piece of javascript that checks if the cookie exists.  I don't care what information the cookie holds because it doesn't matter.  I just want to know if the cookie exists.  If it doesn't exist, I'm going to redirect to an 'Error' page.  Any ideas?
0
GorGor1
Asked:
GorGor1
  • 3
  • 2
1 Solution
 
GorGor1Author Commented:
when I say 'each page', I mean that I'm going to include a piece of javascript on each HTML page.
0
 
COBOLdinosaurCommented:
if (!document.cookie)
{
  //your re-direction code goes here
}




Cd&
0
 
GorGor1Author Commented:
How does that code know which cookie I'm looking for?
0
 
COBOLdinosaurCommented:
Sorry brain fart:

var offset=-1;
if (document.cookie.length > 0) {
offset = document.cookie.indexOf("yourname=");}
if (offset == -1) { //re-direction code}


Cd&
0
 
COBOLdinosaurCommented:
Glad I could help.  Thanks for the A. :^)

Cd&
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now