11. juni 2002 - 11:55Der er
14 kommentarer og 1 løsning
dato til profil
Jeg vil gerne have når folk logger ind at så den skriver i db`en hva tidspunkt og dato de logger ind. men jeg ved ikke hvordan jeg skriver det i login filen.
Nogen der kan hjælpe?
her er login scriptet.
<% Dim sql,rsUser,username,password,page,stayloggedin,LConnectString,lconn,sqlflag
'Grab the submitted variables (page is the page they've come from, set by the hidden variable at the login box) username = Request.Form("username") password = Request.Form("password") page = Request.Form("page") stayloggedin = Request.Form("stayloggedin")
'Check no s**t is trying to hack in using SQL commands if InStr(username, "'") or InStr(username, """") or InStr(username, "=") or InStr(password, "'") or InStr(password, """") or InStr(password, "=") then sqlflag = True end if
if sqlflag <> true then 'Open connection %> <!--#include file="conn.asp"--> <%
'Get a recordset corresponding to the submitted username and password sql = "SELECT username FROM users WHERE username = '" & username & "' AND password = '" & password & "'" Set rsUser = Server.CreateObject("ADODB.Recordset") rsUser.Open sql, conn, 3, 3
'If there was a valid recordset there, then send them back to the page they came from, with the username cookie set If (not rsUser.BOF) and (not rsUser.EOF) and sqlflag <> True then Response.Cookies("username") = rsUser("username") 'If the user wants to stay logged in all the time, then we'll set the cookie with a far-away expiry date if stayloggedin = "yes" then Response.Cookies("username").expires = #1/1/2010#
end if rsUser.close set rsUser = nothing conn.close set conn = nothing Response.Redirect(page) end if
'Otherwise, display an invalid entry screen rsUser.close set rsUser = nothing conn.close set conn = nothing
else end if %>
<font size="3" face="Garamond">Forkert brugernavn eller password </font> <p align="center">
Du kan lave et statement i stil med "UPDATE Users SET LastLogin = now() WHERE UserName = '" & UserName & "'" i eks. Access, getdate() i stedet for now() på SQL Server.
Hvis du vil indsætte en record i en log, er det eks. "INSERT INTO LogTabel(UserName, LogonTime) VALUES('" & UserName & "', now())"
Jo, men du skal så huske at fortælle om den blot skal opdatere et felt i users tabellen eller om den skal indsætte det i en logtabel. Tabel- og feltnavne samt gerne datatyper er også nødvendige.
Jeg poster i givet fald resultatet her, iht. Eksperten's regler om at gøre løsninger tilgængelige for alle :-)
Hvis du vil have at den skal skrive hver gang de logger ind, har du vel lavet en logtabel med eks. username og tidspunkt ? Hvis ikke, skal en sådan laves.
Hvis du kun er interesseret i sidste login, kan du nøjes med at lave et lastlogin felt på din users tabel.
Under forudsætning af, at felter hedder lastlogin og at det er i dato/tid format vil dette virke:
<% Dim sql,rsUser,username,password,page,stayloggedin,LConnectString,lconn,sqlflag,dato,date
'Grab the submitted variables (page is the page they've come from, set by the hidden variable at the login box) username = Request.Form("username") password = Request.Form("password") page = Request.Form("page") stayloggedin = Request.Form("stayloggedin")
'Check no s**t is trying to hack in using SQL commands if InStr(username, "'") or InStr(username, """") or InStr(username, "=") or InStr(password, "'") or InStr(password, """") or InStr(password, "=") then sqlflag = True end if
if sqlflag <> true then 'Open connection %> <!--#include file="conn.asp"--> <%
'Get a recordset corresponding to the submitted username and password sql = "SELECT username FROM users WHERE username = '" & username & "' AND password = '" & password & "'" Set rsUser = Server.CreateObject("ADODB.Recordset") rsUser.open sql , conn, 3, 3
'If there was a valid recordset there, then send them back to the page they came from, with the username cookie set If (not rsUser.BOF) and (not rsUser.EOF) and sqlflag <> True then Response.Cookies("username") = rsUser("username") 'If the user wants to stay logged in all the time, then we'll set the cookie with a far-away expiry date if stayloggedin = "yes" then Response.Cookies("username").expires = #1/1/2010# end if ' her er brugeren logget ind ' Opbyg SQL statement ved brug Access' indbyggede now() funktion strSQL = "UPDATE Users SET LastLogin = now() WHERE UserName = '" & UserName & "'"
' udfør SQL statement i databasen conn.Execute(strSQL)
rsUser.close set rsUser = nothing conn.close set conn = nothing Response.Redirect(page) end if
'Otherwise, display an invalid entry screen rsUser.close set rsUser = nothing conn.close set conn = nothing
else end if %>
<font size="3" face="Garamond">Forkert brugernavn eller password </font> <p align="center">
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.