If cookie exists

Hey,

I can't seem to find a resource with ASP to see if a cookie exists and then call "something"

I am trying to find:

If cookie exists

redirect home.asp

else

login.asp

Basic like that.

Thanks,

Ryan
LVL 1
catonthecouchproductionsAsked:
Who is Participating?
 
Corrup7ioNCommented:
if Request.Cookies("cookiename") <> "" then
   ....

If you request a cookie that doesn't exist, an empty string is returned. If you're using a cookie to resume a session or something like that, make sure you validate the cookie value against a database before you redirect.
0
 
Loganathan NatarajanLAMP DeveloperCommented:
0
 
catonthecouchproductionsAuthor Commented:
I saw that, but I didn't see how to check for the cookie?

Ryan
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
hieloCommented:
>>If cookie exists
>>redirect home.asp
>>else
>>login.asp

Wouldn't you be better off using a Session instead of a Cookie? If the user remains idle for some time the Session will expire an the user will be force to login again. So in home.asp you would use:

'if a session does not exist, send user to login page
If Session("sessionName") = "" Then
 Response.Redirect "login.asp"
End If
0
 
catonthecouchproductionsAuthor Commented:
Thanks hielo! I will try that and cookies, I am just trying to compare some stuff, breaking the ice here with ASP, I have the following code below that is the form action "process-login.asp" but it wont set the cookies.
<%
' declare variables
dim user,pass
 
' set cookies and expire one month from Nov 12
Response.Cookies("user") = Request.Form("username")
Response.Cookies("user").Expires=#Nov 12,2008#
Response.Cookies("pass") = Request.Form("password")
Response.Cookies("pass").Expires=#Nov 12,2008#
 
Response.Redirect "home.asp"
 
 
%>

Open in new window

0
 
hieloCommented:
>>but it wont set the cookies.
This:
Response.Cookies("user").Expires=#Nov 12,2008#

implies Nov 12, 2008 00:00:00

So, the date has expired already. You need to specify  a future date:
Response.Cookies("user").Expires=#Nov 14, 2008#
0
 
catonthecouchproductionsAuthor Commented:
I meant to set that to Thanksgiving, careless error on my part.

Thank you,

Ryan
0
 
hieloCommented:
>>I meant to set that to Thanksgiving,
LOL. Man were you off?
0
 
catonthecouchproductionsAuthor Commented:
Thanks for your help everyone!

...yeah... I was of, early thanksgiving this year.
0
 
hieloCommented:
glad to help. Take care ( or should I say, "take a break")? :)
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.

All Courses

From novice to tech pro — start learning today.