Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with setting cookies

Status
Not open for further replies.

TonyU

Technical User
Joined
Feb 14, 2001
Messages
1,317
Location
US

I'm trying to set a cookie after the user logs in but I'm having problems setting it with the code below in green . Can someone help me please? Thanks

After they log in, I'm appending this code:
<%
if request.cookies(&quot;username&quot;)(&quot;password&quot;) = &quot;&quot; then
response.redirect &quot;login.asp&quot;
end if
%>


to the rest of my pages.


Log In Page Code
<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<!--#include file=&quot;Connections/postcards.asp&quot; -->
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables(&quot;URL&quot;)
If Request.QueryString<>&quot;&quot; Then MM_LoginAction = MM_LoginAction + &quot;?&quot; + Request.QueryString
MM_valUsername=CStr(Request.Form(&quot;login&quot;))
If MM_valUsername <> &quot;&quot; Then
MM_fldUserAuthorization=&quot;&quot;
MM_redirectLoginSuccess=&quot;Welcome.asp&quot;
MM_redirectLoginFailed=&quot;login.asp?valid=false&quot;
MM_flag=&quot;ADODB.Recordset&quot;
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_postcards_STRING
MM_rsUser.Source = &quot;SELECT username, password&quot;
If MM_fldUserAuthorization <> &quot;&quot; Then MM_rsUser.Source = MM_rsUser.Source & &quot;,&quot; & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & &quot; FROM Members WHERE username='&quot; & MM_valUsername &&quot;' AND password='&quot; & CStr(Request.Form(&quot;password&quot;)) & &quot;'&quot;
MM_rsUser.CursorType = 0
MM_rsUser.CursorLocation = 2
MM_rsUser.LockType = 3
MM_rsUser.Open

If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
' username and password match - this is a valid user
'******************* write cookie **********************
Session(&quot;MM_Username&quot;) = MM_valUsername
Session(&quot;MM_Password&quot;) = MM_valPassword
' Response.Cookies(&quot;Username&quot;).Expires = Date - 1
' Response.Cookies(&quot;Password&quot;).Expires = Date - 1
'******************* write cookie **********************
Response.Cookies(&quot;username&quot;) = MM_valUsername
Response.Cookies(&quot;password&quot;) = MM_valPassword
'******************* write cookie **********************


If (MM_fldUserAuthorization <> &quot;&quot;) Then
Session(&quot;MM_UserAuthorization&quot;) = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
Else
Session(&quot;MM_UserAuthorization&quot;) = &quot;&quot;
End If
if CStr(Request.QueryString(&quot;accessdenied&quot;)) <> &quot;&quot; And false Then
MM_redirectLoginSuccess = Request.QueryString(&quot;accessdenied&quot;)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>

[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
I think it is the date -1 that's doing it - your setting it to expire yesterday.

Try something like this
<%
Response.Cookies(&quot;username&quot;) MM_valUsername
Response.Cookies(&quot;username&quot;).Expires = Date + 28

Response.Cookies(&quot;password&quot;) = MM_valPassword
Response.Cookies(&quot;password&quot;).Exprires = Date + 28
%> &quot;A Ticked-off man takes the bricks others throw at him - and throws them back&quot;

Stuart
 
oops

<%
Response.Cookies(&quot;username&quot;)= MM_valUsername
Response.Cookies(&quot;username&quot;).Expires = Date + 28

Response.Cookies(&quot;password&quot;) = MM_valPassword
Response.Cookies(&quot;password&quot;).Exprires = Date + 28
%> &quot;A Ticked-off man takes the bricks others throw at him - and throws them back&quot;

Stuart
 
Might just be me, but shouldnt the line

&quot;If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then&quot;

be

&quot;If Not MM_rsUser.EOF And Not MM_rsUser.BOF Then&quot;
The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top