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
Solved

Help with cookies

Posted on 2004-03-22
13
240 Views
Last Modified: 2011-09-20
I'm trying to use cookies on my intranet site so that when users visit a certain password protected page, the page will look for a cookie to see if they have already logged in or not, and if they have it will forward them past the login page so they don't have to re-enter their username or password.  I believe the adding part is working (I can get a cookie onto the user's machine after they have successfully logged in once.  But my problem is reading this cookie from the users machine.  It seems that the cookie is only valid while the user's browser is open.  Once the browser is closed and the user tries to access that page again, I get a Page Cannot be Displayed error.  Here is the code:

To add the cookie after a user has logged in:
Response.Cookies("auth") = "yes"
Response.Cookies("auth").Expires = Date + 365

Then to read the cookie if they visit this login.asp page again:
MM_redirectLoginSuccess="Calendars/NewEvent.asp?ID="&Recordset1__MMColParam
MM_redirectLoginFailed="AccessDenied.htm"

If (Request.Cookies("auth") = "yes") Then
      Response.redirect(MM_redirectLoginSuccess)
End If

the MM_redirectLoginSuccess variable is the page that is displayed after you successfuly login and I want to automatically send the user there if they have this cookie (auth) with a value of yes.  

If you need to see more code just ask!

Thanks
0
Comment
Question by:sre23
  • 7
  • 6
13 Comments
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 10650890
You are missing the Key Value


try

Response.Cookies("MYCOOKIE")("auth") = "yes"

so add ("MYCOOKIE") to all of your Cookie Call's.

Cookie requires two parts.
1. Cookie name
2. Cookie Key

You must create the cookie before the HTTP headers are written to the client browser. Basically that means you need to create cookies before the <HTML> tag on your page.
0
 
LVL 1

Author Comment

by:sre23
ID: 10650992
so when I add the cookie the code should be:

Response.Cookies("MYCOOKIE")("auth") = "yes"
Response.Cookies("MYCOOKIE")("auth").Expires = Date + 365

and then when I try to read the cookie it should be:

If (Request.Cookies("MYCOOKIE")("auth") = "yes") Then
    Response.redirect(MM_redirectLoginSuccess)
End If

Is this correct?
0
 
LVL 1

Author Comment

by:sre23
ID: 10651006
that can't be right because when I try that I get a page cannot be displayed error when trying to add the cookie to the user's machine.  What am I missing?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 23

Expert Comment

by:Saqib Khan
ID: 10651048
Please Post the Whole error message
0
 
LVL 1

Author Comment

by:sre23
ID: 10651123
Microsoft VBScript runtime error '800a01b6'

Object doesn't support this property or method: 'Response.Cookies(...)'

/MG_Info/Login.asp, line 56

Line 56 is Response.Cookies("MGC")("auth").Expires = Date + 365
0
 
LVL 1

Author Comment

by:sre23
ID: 10651268
Here's the more generic error message:

The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

--------------------------------------------------------------------------------

Please try the following:

Open the mgc home page, and then look for links to the information you want.
Click the  Refresh button, or try again later.

Click  Search to look for information on the Internet.
You can also see a list of related sites.




HTTP 500 - Internal server error
Internet Explorer  
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 10651288
I am sorry, Syntax i mentioned above was for dictionary cookies, you dont really need it.

Code you posted is correct, I dont see any problem with it.

Your Cookies are disabled in browser?
and you generating cookies on the TOP of your page?
0
 
LVL 1

Author Comment

by:sre23
ID: 10651444
yes the code is at the top of the page (before <html>) and I believe cookies are enabled because it works fine until I close the browser.  Once I close the browser and re-open it, it does not work.  I'm not sure if the part that fails is when the browser is trying to access the cookie, or if it fails when it is trying to redirect the user past the current page.

If you notice my redirect page uses a variable from the url and that code comes right before the request for the cookie.  Here is the code starting from the very top to the point that it tries to access the cookie and redirect the user past the login page (the current page).

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="../Connections/conIntranet.asp" -->
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "0"
If (Request.QueryString("ID") <> "") Then
  Recordset1__MMColParam = Request.QueryString("ID")
End If

MM_redirectLoginSuccess="Calendars/NewEvent.asp?ID="&Recordset1__MMColParam
MM_redirectLoginFailed="AccessDenied.htm"

If (Request.Cookies("auth") = "yes") Then      
      Response.redirect(MM_redirectLoginSuccess)
End If
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 10651538
Print the Value on the Top of your Page

<%=Request.Cookies("auth")%>
<% Response.end()%>

What does it show?
0
 
LVL 1

Author Comment

by:sre23
ID: 10651570
ok, I found the problem... the redirect page has security enabled (Restrict Acces To Page behavior) so when I try to forward there automatically I am actually getting sent to the access denied page.  This becomes a whole different problem now.  Is there a way around that?  I've seen sites (such as this one) that have a "Remember Me" feature so that users don't need to log in each time.  I figured the easiest way to do that was with a cookie, but how do you do it?
0
 
LVL 23

Accepted Solution

by:
Saqib Khan earned 50 total points
ID: 10651662
The way you doing is the way to store user name ans password on user Machine.
it is Done with Cookies.

That page has the restrict access, modify that Page to overwrite the Login Process if Cookie is set to True.
0
 
LVL 1

Author Comment

by:sre23
ID: 10651807
thanks so much for your help... sorry to make you take the longest route to fix that one!
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 10651829
No problem:)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dreamweaver CS5.5 Error 5 538
Responsive CSS Layout? 6 50
Dreamweaver CS6 with WordPress 9 119
Wordpress/Dreamweaver Did we get lied to when they created our website? 9 92
For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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