Solved

checking if cookie exists

Posted on 2002-03-29
5
176 Views
Last Modified: 2011-09-20
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
Comment
Question by:GorGor1
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:GorGor1
ID: 6905876
when I say 'each page', I mean that I'm going to include a piece of javascript on each HTML page.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6905947
if (!document.cookie)
{
  //your re-direction code goes here
}




Cd&
0
 
LVL 1

Author Comment

by:GorGor1
ID: 6905958
How does that code know which cookie I'm looking for?
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 50 total points
ID: 6905999
Sorry brain fart:

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


Cd&
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 6926287
Glad I could help.  Thanks for the A. :^)

Cd&
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question