• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1059
  • Last Modified:

Vbscript check if Cookie exists

Hello,

I'm trying to show / hide elements based on  the existence of a cookie; I've tried using this -

<%if Not IsObject(Response.Cookies("user")) then %>
    <li><a href="#" rel="nofollow">Login</a></li>
    <li><a href="#" rel="nofollow">Register</a></li>
<%Else%>
    <li><a href="#" rel="nofollow">Account Settings</a></li>
<%End if%>

Open in new window


but no luck?

Any suggestions

Thank you
0
garethtnash
Asked:
garethtnash
  • 2
  • 2
2 Solutions
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
just check for a blank value:

<%if Response.Cookies("user") = ""  then %>
    <li><a href="#" rel="nofollow">Login</a></li>
    <li><a href="#" rel="nofollow">Register</a></li>
<%Else%>
    <li><a href="#" rel="nofollow">Account Settings</a></li>
<%End if%>

Open in new window

0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You guys are very close.... off by one word.    You are looking for request.cookies, not response.cookies.  Response.cookies sets the cookie and request.cookies gets the cookie.  I know you knew that, probably just over looked.

FYI, you can request and set cookies via javascript/jquery if needed too.

Also,  it is a good idea to obfuscate the user cookie and create a token.  See my answer here that is very similar http:/Q_28641013.html
0
 
garethtnashAuthor Commented:
Hey Scott, can you provide that link again please.

Thank you
0
 
garethtnashAuthor Commented:
Tank you
0
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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