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("username"
("password"
= "" then
response.redirect "login.asp"
end if
%>
to the rest of my pages.
Log In Page Code
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/postcards.asp" -->
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL"
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Request.QueryString
MM_valUsername=CStr(Request.Form("login"
)
If MM_valUsername <> "" Then
MM_fldUserAuthorization=""
MM_redirectLoginSuccess="Welcome.asp"
MM_redirectLoginFailed="login.asp?valid=false"
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_postcards_STRING
MM_rsUser.Source = "SELECT username, password"
If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM Members WHERE username='" & MM_valUsername &"' AND password='" & CStr(Request.Form("password"
) & "'"
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("MM_Username"
= MM_valUsername
Session("MM_Password"
= MM_valPassword
' Response.Cookies("Username"
.Expires = Date - 1
' Response.Cookies("Password"
.Expires = Date - 1
'******************* write cookie **********************
Response.Cookies("username"
= MM_valUsername
Response.Cookies("password"
= MM_valPassword
'******************* write cookie **********************
If (MM_fldUserAuthorization <> ""
Then
Session("MM_UserAuthorization"
= CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
Else
Session("MM_UserAuthorization"
= ""
End If
if CStr(Request.QueryString("accessdenied"
) <> "" And false Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied"
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>
After they log in, I'm appending this code:
<%
if request.cookies("username"
response.redirect "login.asp"
end if
%>
to the rest of my pages.
Log In Page Code
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/postcards.asp" -->
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL"
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Request.QueryString
MM_valUsername=CStr(Request.Form("login"
If MM_valUsername <> "" Then
MM_fldUserAuthorization=""
MM_redirectLoginSuccess="Welcome.asp"
MM_redirectLoginFailed="login.asp?valid=false"
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_postcards_STRING
MM_rsUser.Source = "SELECT username, password"
If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM Members WHERE username='" & MM_valUsername &"' AND password='" & CStr(Request.Form("password"
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("MM_Username"
Session("MM_Password"
' Response.Cookies("Username"
' Response.Cookies("Password"
'******************* write cookie **********************
Response.Cookies("username"
Response.Cookies("password"
'******************* write cookie **********************
If (MM_fldUserAuthorization <> ""
Session("MM_UserAuthorization"
Else
Session("MM_UserAuthorization"
End If
if CStr(Request.QueryString("accessdenied"
MM_redirectLoginSuccess = Request.QueryString("accessdenied"
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>
[tt]"A Successful man is one who can build a firm foundation with the bricks that others throw at him"[/tt]
![[noevil] [noevil] [noevil]](/data/assets/smilies/noevil.gif)
![[noevil] [noevil] [noevil]](/data/assets/smilies/noevil.gif)