If cookie exists


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



Basic like that.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Loganathan NatarajanLAMP DeveloperCommented:
catonthecouchproductionsAuthor Commented:
I saw that, but I didn't see how to check for the cookie?

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

>>If cookie exists
>>redirect home.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
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

>>but it wont set the cookies.
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#
catonthecouchproductionsAuthor Commented:
I meant to set that to Thanksgiving, careless error on my part.

Thank you,

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

...yeah... I was of, early thanksgiving this year.
glad to help. Take care ( or should I say, "take a break")? :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.