How to restrict simultaneous login with the same user name

Source: Internet
Author: User

My approach to this problem is that the user has an active interval problem. If the time interval is exceeded, it can be considered offline. The latter can log in. If there is no latter, it does not mean that the former needs to be logged in again. Because his session is still there. The smaller the time setting, the more accurate it is.
Code Post it for reference.
Function checkonline () dim IP, rsprv, SQL, prvdbstateprvdbstate = falseif dbstate = false thendbopen () prvdbstate = trueend ifset rsprv = server. createobject ("ADODB. recordset ") if SESSION (" username ") =" "thensql =" select * from [Online] Where sessionid = '"& session. sessionid & "'" rsprv. open SQL, Conn, 1, 3if rsprv. EOF thenrsprv. addnewrsprv ("sessionid") = session. sessionidrsprv ("groupchargelv") =-1 rsprv ("lastac TTime ") = now () rsprv (" userip ") = getiprsprv (" onlinetime ") = 0 rsprv (" userwhere ") = request. servervariables ("http_referer") elsersprv ("userwhere") = request. servervariables ("http_referer") rsprv ("onlinetime") = rsprv ("onlinetime") + datediff ("N", rsprv ("lastacttime"), now ()) rsprv ("lastacttime") = now () end ifrsprv. updatersprv. close () 'response. write "notlogin" else 'response. write "logined" SQL = "select * fro M [Online] Where username = '"& SESSION (" username ") &"' "rsprv. open SQL, Conn, 1, 3if rsprv. EOF thenrsprv. addnewrsprv ("sessionid") = session. sessionidrsprv ("username") = SESSION ("username") rsprv ("groupchargelv") = SESSION ("groupchargelv") rsprv ("lastacttime") = now () rsprv ("onlinetime") = 0 rsprv ("userip") = getiprsprv ("userwhere") = request. servervariables ("http_referer") elseif rsprv ("sessionid") <> sessio N. sessionid and application ("loginset") (1) = false theninfoto "loginout. ASP "," this account has been logged on elsewhere. You can set only one logon ID for one website. You can try logging on later. "Response. end () end ifrsprv ("userwhere") = request. servervariables ("http_referer") rsprv ("onlinetime") = rsprv ("onlinetime") + datediff ("N", rsprv ("lastacttime"), now ()) rsprv ("lastacttime") = now () end ifrsprv. updatersprv. close () end ifset rsprv = nothingif datediff ("S", application ("onlinelastdelete"), now ()> int (Application ("deleteonlinediff") thenapplication. lock () Application ("onlinelastdelete") = nowapplication. unlock () Conn. execute ("delete from [Online] Where datediff ('s ', lastacttime, now ()>" & int (Application ("checkonlinediff ")&"")) 'delete the end ifif prvdbstate = true then dbclose () end function of the guest that has no activity in seconds.

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.