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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie easy one 1

Status
Not open for further replies.

sdh

Programmer
Apr 30, 2001
121
GB
Below is the code Ultradev wrtote for me to login I want to extend this so by writing a cookie the user only has to log in once but i do not seem to be able to write the cookie when a valid user enters. See code in green.
Can anyone tell me why? also how do I get this to work from a checkbox tick and automatically log people past this page
thanks in advance
SDh

MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>&quot;&quot; Then MM_LoginAction = MM_LoginAction + &quot;?&quot; + Request.QueryString
MM_valUsername=CStr(Request.Form(&quot;txtUsername&quot;))
If MM_valUsername <> &quot;&quot; Then
MM_fldUserAuthorization=&quot;access_level&quot;
MM_redirectLoginSuccess=&quot;default2.asp&quot;
MM_redirectLoginFailed=&quot;unauthorised.asp&quot;
MM_flag=&quot;ADODB.Recordset&quot;
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_connweb_STRING
MM_rsUser.Source = &quot;SELECT Login, 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 Users WHERE Login='&quot; & MM_valUsername &&quot;' AND Password='&quot; & CStr(Request.Form(&quot;txtpassword&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
Session(&quot;MM_Username&quot;) = MM_valUsername
Response.Buffer=true
Response.Cookies(&quot;ID&quot;)(&quot;Username&quot;)=MM_valusername
Response.Cookies(&quot;ID&quot;)(&quot;Password&quot;)= MM_rsuser(&quot;Password&quot;)



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
 
What are you getting for an error, or what is or is not happening?
 
I am not getting an error but the cookie is not appearing on my machine ( iam testing the asp page by using pws on the NT machine the page was developed on)

sdh
 
Can you add the following statements after setting the cookies:

Response.Write &quot;<br>&quot; & (Request.Cookies(&quot;ID&quot;)(&quot;Username&quot;)) & &quot;<br>&quot;
Response.Write (Request.Cookies(&quot;ID&quot;)(&quot;Password&quot;)) & &quot;<br>&quot;

To see if the cookies are in fact being set, but not where you are looking for them?
 
Thanks lobstah

It was being written but i cannot find it on the machine.

any ideas were it would be it is not in the cookies folder within my profile or anybody elses profile on this NT machine.
 
If you do not set an expiry date the cookie is kept in the browsers cache, this will remain there until the browser is closed. If you set an expiry date on the cookie it is written to the client disk ( as long as they have the cookies enabled option set on their browser)
 
Thanks sjravee! I had a similar problem because I wasn't setting the expiry date, but I knew the cookie was out there, just didn't know where. So you were able to help me out too!

Thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top