?
Solved

If cookie exists

Posted on 2008-11-12
10
Medium Priority
?
1,857 Views
Last Modified: 2012-05-05
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
0
Comment
10 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 22942304
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 22942348
I saw that, but I didn't see how to check for the cookie?

Ryan
0
 
LVL 3

Accepted Solution

by:
Corrup7ioN earned 1200 total points
ID: 22943369
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 82

Expert Comment

by:hielo
ID: 22944500
>>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
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 22945815
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
 
LVL 82

Assisted Solution

by:hielo
hielo earned 800 total points
ID: 22946730
>>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
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 22946887
I meant to set that to Thanksgiving, careless error on my part.

Thank you,

Ryan
0
 
LVL 82

Expert Comment

by:hielo
ID: 22946927
>>I meant to set that to Thanksgiving,
LOL. Man were you off?
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 22955659
Thanks for your help everyone!

...yeah... I was of, early thanksgiving this year.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22955750
glad to help. Take care ( or should I say, "take a break")? :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

755 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