Solved

checking if cookie exists

Posted on 2002-03-29
5
175 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

856 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