Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

checking if cookie exists

Posted on 2002-03-29
5
Medium Priority
?
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

598 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