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 Westi 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 - posted in the DW forum 2 - Urgent

Status
Not open for further replies.

TonyU

Technical User
Feb 14, 2001
1,317
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]
 
Well, you are writing two cookies here:

Response.Cookies(&quot;username&quot;) = MM_valUsername
Response.Cookies(&quot;password&quot;) = MM_valPassword

but trying to call one cookie here:

<%
if request.cookies(&quot;username&quot;)(&quot;password&quot;) = &quot;&quot; then
response.redirect &quot;login.asp&quot;
end if
%>

So change your call to something like this:

<%
if request.cookies(&quot;username&quot;) = &quot;&quot; then
response.redirect &quot;login.asp&quot;
end if
if request.cookies(&quot;password&quot;) = &quot;&quot; then
response.redirect &quot;login.asp&quot;
end if
%>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top