PDA

View Full Version : Login/logout Time


Abd
04-29-2003, 05:12 PM
Hi All,

my Application, at login stores the system time, and at logout stores system time and redirect to the login page, there after, it compute the difference in time as the Log Time, this Log Time is inserted ino the Database.

My problem is that even before login, on loading the login page it insert a time into the Database because my ASP code that handle DatedDiff and inserting is in the login page. I NEED HELP, SO THAT ON LOADING THE LOGIN PAGE IT DOES NOT INSERT INTO THE DATABASE EXCEPT IF IT WAS REDIRECTED FROM LOGOUT PAGE.

Bellow is my code;

sessionlength=DateDiff("s", session("logintime"), Now )

dim con
set con=server.CreateObject("adodb.connection")

con.Open "PROVIDER=SQLOLEDB;DATA SOURCE=ARahim4-OFS;UID=sa;PWD=;DATABASE=abdul"

dim rs
set rs = server.CreateObject("adodb.recordset") 'recordset object creation

dim sql,username

sql="INSERT INTO crmcalltime (calltime,crmuser,crmdate) VALUES (thelength,'theuser','thedate')"

sql=replace(sql,"thelength",sessionlength )
sql=replace(sql,"theuser",session("username") )
sql=replace(sql,"thedate",session("crmdate") )

rs.Open sql, con

Thanks
Abdul

raf
04-29-2003, 09:09 PM
The easiest sollution is just move all the code to the logoutpage and make the insert before the redirect.

Simple as that.

Ot, if this is not possible for some obscure reason, just set a flag on the logoutpage and check for the flag on top of the loginpage, or include some strange variable and value to the querystring when you redirect on the logoutpage and check the querystring on top of the loginpage.

Abd
04-30-2003, 10:44 AM
Hi raf,

I tried the variable value, querystring stuff, Application runs smoothly but DID NOT insert the login time into the DB. Can you help with may be a sample code on the variable value, querystring.

Thanks
Abd

raf
04-30-2003, 07:34 PM
Abd,

don't want to put you down or so, buth this is all quite basic stuff, and you should really first study some basic html, sql and vbscript.

looking at sample code and modifying that is not the best way to learn asp.

if you want to include the logintime, you just need to have a variable for that in your db + insert this extra value. Like


sql="INSERT INTO crmcalltime (logintime,calltime,crmuser,crmdate) VALUES (#thelogin#,thelength,'theuser','thedate')"

sql=replace(sql,"thelogin",session("logintime") )
sql=replace(sql,"thelength",sessionlength )
sql=replace(sql,"theuser",session("username") )
sql=replace(sql,"thedate",session("crmdate") )


If it's a date-time variable in your db, the value needs to be enclosed in #