PDA

View Full Version : Bizzare non appearance of cookie


peaceful
11-25-2002, 01:38 PM
Hi there,

I'm pretty new to this programming lark (although I used to make my Amstrad CPC464 draw houses in basic ;)

With a little help from ASP for dummies, i've managed to write a login system - it checks against an access database for username and password, and then redirects the users to the page appropriate to their level of access within the organisation I work for (a national education charity in the UK)...So far, so extrememly exciting (for me at least :)

However, for some bizzare reason, the part of the code which, having accertained their level of access is then supposed to write a cookie, very much appears to be not doing so at all!

I'll paste the code in below - the whole page in case for some reason something earlier in the code is stopping it from working...please be gentle with it as it's the first programme i've written for 15 years...:)

Thanks very much...
Paul
<% Option Explicit %>
<!-- #include virtual="common/adovbs.inc" -->
<%
Dim connect, records, query, level
set connect = Server.CreateObject("ADODB.Connection")
connect.open "list"
set records = Server.CreateObject("ADODB.Recordset")
query = "SELECT Username,Password,Access FROM list"
records.Open Query, Connect, adOpenDynamic
records.MoveFirst
Do until records.EOF
If records ("Username") = Request("Username") And records ("Password") = Request("Password") then
If records ("Access") = "Fellow" Then
response.Cookies("members")("level") = "Fellow"
response.Redirect("fellows.asp")
ElseIf records ("Access") = "Team" Then
Response.Cookies("members")("level") = "Team"
response.Redirect("Team.asp")
ElseIf records ("Access") = "PM" Then
response.Cookies("members")("level") = "PM"
response.Redirect("PM.asp")
ElseIf records ("Access") = "Assoc" Then
response.Cookies("members")("level") = "Assoc"
response.Redirect("Assoc.asp")
End If
End If
records.MoveNext
loop
Response.Redirect("error.asp")
%>

Roelf
11-25-2002, 02:16 PM
if you donīt provide an expiration date for the cookie, it will be a session only cookie. the cookie is not saved in the cookies folder.
try setting the Response.Cookies("member").Expires attribute to an appropriate value, see http://www.devguru.com/Technologies/asp/quickref/response_cookies.html
or even better: http://www.w3schools.com/asp/asp_cookies.asp

peaceful
11-25-2002, 02:23 PM
Thank you very much!

Of course - it's amazing how these things click into place!

I actually only want it to last for the duration of the session - I want subsequent pages to check that it is there and don't want it to last longer than the session...

I'll be back next time I have a problem! :rolleyes: