This topic is locked

Track # of Login

6/10/2004 23:05:58
ASPRunnerPro General questions
B
berga@alpenacc.net author

SImply put, I was wondering if there is a SIMPLE way to add a record to a database of the username that was logged in, the time, and the date of each sucessfull login. The sole reason for this, is to show how much use the database is getting. Here's the situation:
I have a database called Users.mdb, the table name is also users. I would like to add a seperate table (logins) and each time a person logs in, it would put their username, date and time in the logins table.
Is this possible??
Thanks in advance!!!

Sergey Kornilov admin 6/16/2004

Sure you can do this.
You will need to modify login.asp file to insert the following code snippet right before you redirect a user to the list page:

strSQL = "insert into logins (Username, LoggedIn) values ('" & Session("UserID") & "', Now())" 

dbConnection.Execute strSQL


I hope this helps.

B
berga@alpenacc.net author 6/21/2004

Works great, Thanks a million!
Also, is there any way to show where they are?
i.e. Each login page is directed to the Users database, which is central to the login page. After they login, they can access each of my databases (they have to seperately login to each but same username and password). So my question, can I also add in the logins table which of the 4 databases they were accessing? Even putting the FIRSTPAGE that they are directed to such as ####_List.asp, then that would give me the data source they are accessing!!
Thanks again!

B
berga@alpenacc.net author 6/30/2004

Is the above not possible? Thanks.

Sergey Kornilov admin 6/30/2004

You also need to insert a database name into the table where you track number of logins. Since I don't know your application logic I cannot give you more detailed advise.

Sarjent 9/9/2004

Would you use the LOGON_USER variable to get the name of the current windows logged in user?
Basically I am attempting to add a record of when a entry is added or edited from the database that consists of the current logged in Windows username (this is a domain so we use NTLM authentication for access to the pages) and the time the entry happened.
So I assume I would edit the _edit.asp page someplace with the same information that is here?
I've put this code in _edit.asp and its not really working
<!-- 1USERNAME RECORD INSERT -->

strFields = strFields & (Log_Who, Log_Time)

strValues = strValues & "'" & mid(Request.ServerVariables("LOGON_USER") & "', Now())"

<!-- 1END USERNAME RECORD INSERT -->

Sergey Kornilov admin 9/10/2004

Hi,
you can try something like this:

strFields = strFields & ", Log_Who, Log_Time"

strValues = strValues & ",'" & mid(Request.ServerVariables("LOGON_USER") & "', Now()"


Actual ASP code depends on where exactly you trying to insert it.

Sarjent 9/10/2004

I am trying to insert it into a database called DMSC and a table called DMSC_QUERY in SQL. Log_Who, and Log_Time are columns in the DMSC_QUERY table. These would hopefully be inserted from the add or edit page into the record that was added or edited. Definetly not into a seperate table or anything.
So what I've done now is made the time stamp a hidden field on add/edits. I tried to do the same for LOGON_USER but I put that as the field's default in quotes and all the database gets is an entry that says LOGON_USER instead of the username

Sarjent 9/15/2004

any idea on what I can do to fix this? Its partially working and I'd like to get it all the way done. I've tried numerous things with different variabels but I am stuck. Thanks! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2490&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />

Sergey Kornilov admin 9/15/2004

Hi,
try to print exact SQL query on the Web page before you execute it. If you post SQL query here I can tell you what exactly is wrong.

Sarjent 9/15/2004

I think this is what you want from the _edit.asp file

if Request.form("action")="add" or Request.form("action")="added" then

sMode = "Add"

strSQL="select " & AddWrappers("Thiskey") & ", " & AddWrappers("WeekStart") & ", " & AddWrappers("Name") & ", " & AddWrappers("Holiday") & ", " & AddWrappers("Log_Time") & ", " & AddWrappers("Log_Who") & ", "
if InStr(1, LCase(strSQL), LCase(AddWrappers(strKeyField)))<1 then strSQL = "select " & AddWrappers(strKeyField) & ", " &  Mid(strSQL, 8) '1

if strKeyField2<>"" and InStr(1, LCase(strSQL), LCase(AddWrappers(strKeyField2)))<1 then strSQL = "select " & AddWrappers(strKeyField2) & ", " &  Mid(strSQL, 8)

if strKeyField3<>"" and InStr(1, LCase(strSQL), LCase(AddWrappers(strKeyField3)))<1 then strSQL = "select " & AddWrappers(strKeyField3) & ", " &  Mid(strSQL, 8)
if Right(strSQL,2)= ", " then strSQL = Left(strSQL, Len(strSQL)-2) '1

strSQL = strSQL & " from " & strTableName & " where 1<0"
Response.Write "<h1>Add new record</h1>"

else

sMode = "Edit"

strSQL="select " & AddWrappers("Thiskey") & ", " & AddWrappers("WeekStart") & ", " & AddWrappers("Name") & ", " & AddWrappers("Holiday") & ", " & AddWrappers("Log_Time") & ", " & AddWrappers("Log_Who") & ", "


in /include/_aspfunctions.asp

' returns field's default value

CDomID = Request.ServerVariables("LOGON_USER")

function GetDefaultValue(strField)

 if strField="Thiskey" then GetDefaultValue = "" end if

 if strField="WeekStart" then GetDefaultValue = "" end if

 if strField="Name" then GetDefaultValue = "" end if

 if strField="Holiday" then GetDefaultValue = "" end if

 if strField="Log_Time" then GetDefaultValue = "NOW()" end if

 if strField="Log_Who" then GetDefaultValue = "CDomID" end if



if LCase(GetDefaultValue) = "now()" then GetDefaultValue=now() end if

end function
Sergey Kornilov admin 9/15/2004

No,
I need actual SQL query.
Put the following code before you executethis query:

Response.Write strSQL

Response.Flush


This will print SQL query on the webpage.

Sarjent 9/15/2004
update [dbo].[onCall] set Thiskey=1, WeekStart='1/5/2004', Name='Shan', Holiday='test1', [Log_Time]='9/15/2004 8:03:31 AM', [Log_Who]=''


Thats what it spit out.

Sergey Kornilov admin 9/16/2004

This SQL query looks good except for empty Log_Who variables.
You need to check if Request.ServerVariables("LOGON_USER") populated with logged user name. Just put somewhere on the ASP page the following code:

Response.Write "LOGON_USER: " & Request.ServerVariables("LOGON_USER")

Response.Flush

Sarjent 9/16/2004

I think this might be it..
http://www.kbalertz.com/Feedback_188717.aspx
This article was previously published under Q188717

SYMPTOMS

Accessing the Request.ServerVariables("LOGON_USER") variable from Active Server Pages (ASP) returns an empty string.

CAUSE

The LOGON_USER variable is not populated if you use the Allow Anonymous security to access the ASP page.
In order for the LOGON_USER variable to be populated, the user must be authenticated using either Basic or NT Challenge/Response security.

STATUS

This behavior is by design.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

142868 IIS: Authentication and Security Features

501070 9/22/2004

Hello,
A while ago, I originally started this thread. I responded to know if I could not only add the username and time that the use logged in, but add the database that they accessed. You replied with that you needed more info for this.
I have four databases - case, green, hillman, and ocqueoc
That is the name of the databases and the directory they are in.
Also, I have a field in my Users database (tables are Users and logins) fields in the logins tables are username, loggedin, and database.
I don't need anything specific, but just able to differentiate between case, green, etc. So if I can just put a filename such as (case_list.asp) in that field, that would be fine.
Each seperate database is launched from a seperate database link. So the link for case, directs them to //asp/case/case_login.asp
Within the case_login.asp it refers to the //asp/users/db/users.mdb file for user information where logins are recorded, new users are entered and validated.
Any help would be great.
Thanks.

501071 9/26/2004

After thinking about this....I figured the current code may help.

Below is the current codeing that I am using to put the username and logged in time for the user. It works Great!!!! Thanks for that advice.
Further, I would think the first part would be simple to modify....just add "database" to the (username, loggedin, database)
It's the second part that gets me....I see the session UserID, and the Now for the time....but I would need to add on the end some file name (like I was suggesting in my previous post). HELP! Thanks.
strSQL = "insert into logins (Username, LoggedIn) values ('" & Session("UserID") & "', Now())"

dbConnection.Execute strSQL

T
thunderwonder 10/4/2004

[B][FONT=Times]Hi,

I had a Project named Customer Interaction System which is accessed by atleast six user out of them I will be the administrator who has all the rights and permissions but I dont want the other users to click on the Link which I had provided on my menu_list.asp page or else if the other users click on the link it should prompt them for the admin id and password.

can I do that??????? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2585&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2585&image=2&table=forumreplies' class='bbc_emoticon' alt=':(' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2585&image=3&table=forumreplies' class='bbc_emoticon' alt=':(' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=2585&image=4&table=forumreplies' class='bbc_emoticon' alt=':(' />

L
laboria 10/27/2004

In reference to this subject, I am a little confused about exactly what code is needed and where it needs to be posted.
I am tying to have the user's Logon ID automatically inputted into the same database that is edited/updated. The table name is MAILTRACKING, the filed name is TECH. I have the Date field setup and working to auto date through access.
Thanks.