[Asp] Count online users

Source: Internet
Author: User
Tags servervariables

Statistics of previous ASP versions are online. Because it is extracted from the previous system. To use this function, modify it.

 

If cbool (Application ("markonline") = true then checkonline ()
Function checkonline ()
Dim IP, rsprv, SQL
If dbstate = false then dbopen ()
Set rsprv = server. Createobject ("ADODB. recordset ")
If SESSION ("username") = "" then
SQL = "select * from [Online] Where sessionid = '" & session. sessionid &"'"
Rsprv. Open SQL, Conn, 1, 3
If rsprv. EOF then
Rsprv. addnew
Rsprv ("sessionid") = session. sessionid
Rsprv ("groupchargelv") =-1
Rsprv ("lastacttime") = now ()
Rsprv ("userip") = getip
Rsprv ("onlinetime") = 0
Rsprv ("userwhere") = request. servervariables ("http_referer ")
Else
Rsprv ("userwhere") = request. servervariables ("http_referer ")
Rsprv ("onlinetime") = rsprv ("onlinetime") + datediff ("N", rsprv ("lastacttime"), now ())
Rsprv ("lastacttime") = now ()
End if
Rsprv. Update
Rsprv. Close ()
'Response. Write "notlogin"
Else
'Response. Write "logined"
SQL = "select * from [Online] Where username = '" & SESSION ("username ")&"'"
Rsprv. Open SQL, Conn, 1, 3
If rsprv. EOF then
Rsprv. addnew
Rsprv ("sessionid") = session. sessionid
Rsprv ("username") = SESSION ("username ")
Rsprv ("groupchargelv") = SESSION ("groupchargelv ")
Rsprv ("lastacttime") = now ()
Rsprv ("onlinetime") = 0
Rsprv ("userip") = getip
Rsprv ("userwhere") = request. servervariables ("http_referer ")
Else
If rsprv ("sessionid") <> session. sessionid and application ("loginset") (1) = false then
Response. Write ("<SCRIPT> alert ('this account has been logged in elsewhere, and only one login ID can be set for the website \ n. You can try logging in later. '); Location. href = 'loginout. asp '")
Response. End ()
End if
Rsprv ("userwhere") = request. servervariables ("http_referer ")
Rsprv ("onlinetime") = rsprv ("onlinetime") + datediff ("N", rsprv ("lastacttime"), now ())
Rsprv ("lastacttime") = now ()
End if
Rsprv. Update
Rsprv. Close ()
End if

If datediff ("S", application ("onlinelastdelete"), now ()> int (Application ("deleteonlinediff") then
Application. Lock ()
Application ("onlinelastdelete") = now
Application. Unlock ()
Conn. execute ("delete from [Online] Where datediff ('s ', lastacttime, now ()>" & int (Application ("checkonlinediff ")&"")) 'delete no active visitor in X seconds
End if
Set rsprv = nothing
End Function

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.