Morgoth
12-01-2002, 08:54 AM
I have done it! Online Members that run under a personal Timeout script. Starting page is login.asp
I have 3 pages and a db:
Login/Logout page
Display page
Timeout page
The Database layout is at the bottom:
Now your timeout page will be all over your site and included in either your config file or in a new include file. It checks to see if you are logged in by cookies (you can personalize it yourself with sessions or whatever...) and updates your loggedin time. It also checks other accounts to see if their logged in times are less then or equal to 15 minutes, if not, it changes it to false.
You will understand when you read the code (remember to include this on all the pages you want to display this on, other pages doesn't matter, it only needs to be checked and updated if someone is going to see who is online.):
<%
Set oConn = Server.CreateObject("ADODB.Connection")
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb") & ";"
oConn.Open StrConn
CookieID = Request.Cookies("Login")("CookieID")
Cookieacctname = Request.Cookies("Login")("Cookieacctname")
Cookieacctpassword = Request.Cookies("Login")("Cookieacctpassword")
intTimeoutTime = 15 'In whole number minutes
If CookieID <> "" AND Cookieacctname = "valid" OR Cookieacctpassword = "valid" Then
sSQL = "UPDATE tblMembers SET LoggedinDate=#" & Now() & "# WHERE (ID=" & CookieID & ")"
Set oRS = oConn.Execute(sSQL)
End If
sSQL = "SELECT * FROM tblMembers ORDER BY ID ASC"
Set oRS = oConn.Execute(sSQL)
Do Until oRS.EOF
If DateDiff("n", oRS("LoggedinDate"), Now()) <= intTimeoutTime Then
blnLoggedin = True
Else
blnLoggedin = False
End If
ssSQL = "UPDATE tblMembers SET Loggedin=" & blnLoggedin & " WHERE (ID=" & oRS("ID") & ")"
Set ooRS = oConn.Execute(ssSQL)
oRS.MoveNext
Loop
oConn.Close
%>
Display Page (This is basic, but you might need it to view the effects):
<!--#INCLUDE FILE="timeout.asp" -->
<%
Set oConn = Server.CreateObject("ADODB.Connection")
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb") & ";"
oConn.Open StrConn
sSQL = "SELECT * FROM tblMembers WHERE (Loggedin=True)"
Set oRS = oConn.Execute(sSQL)
If oRS.EOF <> True Then
Do Until oRS.EOF
Response.Write oRS("username") & "<br>"
oRS.MoveNext
Loop
End If
Response.Write "<form method=""post"" action=""login.asp?login=logout"">" & "<br>" & "<input type=""submit"" value=""Logout"">" & "<br>" & "</form>"
oConn.Close
%>
The login and logout file:
<%
Set oConn = Server.CreateObject("ADODB.Connection")
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb") & ";"
oConn.Open StrConn
acctname = Request.Cookies("Login")("Cookieacctname")
acctpassword = Request.Cookies("Login")("Cookieacctpassword")
If acctname <> "valid" AND acctpassword <> "valid" Then
acctname = Request.Form("acctname")
acctpassword = Request.Form("acctpassword")
sSQL = "SELECT * FROM tblMembers WHERE (acctname='" & acctname & "' AND acctpassword='" & acctpassword & "')"
Set oRS = oConn.Execute(sSQL)
If NOT oRS.EOF Then
Response.Cookies("Login")("CookieID") = oRS("ID")
Response.Cookies("Login")("Cookieacctname") = "valid"
Response.Cookies("Login")("Cookieacctpassword") = "valid"
Response.Redirect "display.asp"
Else
%>
<form method="post" action="login.asp">
<table cellpadding="0" cellspacing="5" width="185" border="0">
<tr>
<td><font size="2">Member: </font></td><td><input type="text" name="acctname"></td>
</tr>
<tr>
<td><font size="2">Password: </font></td><td><input type="password" name="acctpassword"></td>
</tr>
<tr>
<td></td><td><input type=submit value="Submit"></td>
</tr>
</table>
</form>
<%
End If
ElseIf Request.QueryString("logout") = "true" Then
sSQL = "UPDATE tblMembers SET LoggedinDate=#01/01/2000 12:00:00AM# WHERE (ID=" & ID & ")" 'This date was choosen because It's 2 years behind.
Set oRS = oConn.Execute(sSQL)
Response.Cookies("Login")("Cookieacctname") = ""
Response.Cookies("Login")("Cookieacctpassword") = ""
Response.Cookies("Login")("CookieID") = ""
Response.Redirect "login.asp"
Else
Response.Redirect "display.asp"
End If
oConn.Close
%>
If you can't see how this works, or if you have a problem installing it, reply to this post and I will help.
If I posted something up there wrong then I will fix it and notify people.
Now this is what the db should look like:
a few fields
atleast 3.
ID field (Auto Number)
Loggedin Field (Yes/No)
LoggedinDate Field (Date)
That's all you need, but you can add what you want to personalize it.
Have fun!
I have 3 pages and a db:
Login/Logout page
Display page
Timeout page
The Database layout is at the bottom:
Now your timeout page will be all over your site and included in either your config file or in a new include file. It checks to see if you are logged in by cookies (you can personalize it yourself with sessions or whatever...) and updates your loggedin time. It also checks other accounts to see if their logged in times are less then or equal to 15 minutes, if not, it changes it to false.
You will understand when you read the code (remember to include this on all the pages you want to display this on, other pages doesn't matter, it only needs to be checked and updated if someone is going to see who is online.):
<%
Set oConn = Server.CreateObject("ADODB.Connection")
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb") & ";"
oConn.Open StrConn
CookieID = Request.Cookies("Login")("CookieID")
Cookieacctname = Request.Cookies("Login")("Cookieacctname")
Cookieacctpassword = Request.Cookies("Login")("Cookieacctpassword")
intTimeoutTime = 15 'In whole number minutes
If CookieID <> "" AND Cookieacctname = "valid" OR Cookieacctpassword = "valid" Then
sSQL = "UPDATE tblMembers SET LoggedinDate=#" & Now() & "# WHERE (ID=" & CookieID & ")"
Set oRS = oConn.Execute(sSQL)
End If
sSQL = "SELECT * FROM tblMembers ORDER BY ID ASC"
Set oRS = oConn.Execute(sSQL)
Do Until oRS.EOF
If DateDiff("n", oRS("LoggedinDate"), Now()) <= intTimeoutTime Then
blnLoggedin = True
Else
blnLoggedin = False
End If
ssSQL = "UPDATE tblMembers SET Loggedin=" & blnLoggedin & " WHERE (ID=" & oRS("ID") & ")"
Set ooRS = oConn.Execute(ssSQL)
oRS.MoveNext
Loop
oConn.Close
%>
Display Page (This is basic, but you might need it to view the effects):
<!--#INCLUDE FILE="timeout.asp" -->
<%
Set oConn = Server.CreateObject("ADODB.Connection")
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb") & ";"
oConn.Open StrConn
sSQL = "SELECT * FROM tblMembers WHERE (Loggedin=True)"
Set oRS = oConn.Execute(sSQL)
If oRS.EOF <> True Then
Do Until oRS.EOF
Response.Write oRS("username") & "<br>"
oRS.MoveNext
Loop
End If
Response.Write "<form method=""post"" action=""login.asp?login=logout"">" & "<br>" & "<input type=""submit"" value=""Logout"">" & "<br>" & "</form>"
oConn.Close
%>
The login and logout file:
<%
Set oConn = Server.CreateObject("ADODB.Connection")
StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db.mdb") & ";"
oConn.Open StrConn
acctname = Request.Cookies("Login")("Cookieacctname")
acctpassword = Request.Cookies("Login")("Cookieacctpassword")
If acctname <> "valid" AND acctpassword <> "valid" Then
acctname = Request.Form("acctname")
acctpassword = Request.Form("acctpassword")
sSQL = "SELECT * FROM tblMembers WHERE (acctname='" & acctname & "' AND acctpassword='" & acctpassword & "')"
Set oRS = oConn.Execute(sSQL)
If NOT oRS.EOF Then
Response.Cookies("Login")("CookieID") = oRS("ID")
Response.Cookies("Login")("Cookieacctname") = "valid"
Response.Cookies("Login")("Cookieacctpassword") = "valid"
Response.Redirect "display.asp"
Else
%>
<form method="post" action="login.asp">
<table cellpadding="0" cellspacing="5" width="185" border="0">
<tr>
<td><font size="2">Member: </font></td><td><input type="text" name="acctname"></td>
</tr>
<tr>
<td><font size="2">Password: </font></td><td><input type="password" name="acctpassword"></td>
</tr>
<tr>
<td></td><td><input type=submit value="Submit"></td>
</tr>
</table>
</form>
<%
End If
ElseIf Request.QueryString("logout") = "true" Then
sSQL = "UPDATE tblMembers SET LoggedinDate=#01/01/2000 12:00:00AM# WHERE (ID=" & ID & ")" 'This date was choosen because It's 2 years behind.
Set oRS = oConn.Execute(sSQL)
Response.Cookies("Login")("Cookieacctname") = ""
Response.Cookies("Login")("Cookieacctpassword") = ""
Response.Cookies("Login")("CookieID") = ""
Response.Redirect "login.asp"
Else
Response.Redirect "display.asp"
End If
oConn.Close
%>
If you can't see how this works, or if you have a problem installing it, reply to this post and I will help.
If I posted something up there wrong then I will fix it and notify people.
Now this is what the db should look like:
a few fields
atleast 3.
ID field (Auto Number)
Loggedin Field (Yes/No)
LoggedinDate Field (Date)
That's all you need, but you can add what you want to personalize it.
Have fun!