Also talk about php website online count statistics
Source: Internet
Author: User
Db layer: db_online.PHP this function enables users to be online and checks the online status of other users. function checkOnline ($ userid, $ tempid = null)
{
$ Conn = connect ();
// For all users
// Set yourself to online first
$ Stmt = "UPDATE". DB_NAME. ". user set IsOnline = 'y' WHERE UserID =". $ userid;
$ Result = query ($ stmt, $ conn );
// Info ($ stmt );
// If the current user is a tourist
If ($ tempid! = Null)
{
$ Stmt = "SELECT TempID FROM". DB_NAME. ". TEMPUSER WHERE
TempID = ". $ tempid;
$ Result = query ($ stmt, $ conn );
// Info ($ stmt );
// If the visitor is still online
If ($ row = fetch_array ($ result ))
{
$ Stmt = "UPDATE". DB_NAME. ". TEMPUSER SET
// Obtain the number of online users, including users and visitors
Function getOnlineNumber ()
{
$ Olnum = array ();
$ Conn = connect ();
$ Stmt = "select count (UserID) FROM". DB_NAME. ". user where IsOnline = 'y' AND
UserGroupID! = 4 "; // 4 is the guest user group id
// Info ($ stmt );
$ Result = query ($ stmt, $ conn );
$ Olnum ['user'] = result ($ result, 0, "COUNT (UserID )");
$ Stmt = "select count (TempID) FROM". DB_NAME. ". TEMPUSER ";
// Info ($ stmt );
$ Result = query ($ stmt, $ conn );
If ($ row = fetch_array ($ result ))
{
$ Olnum ['guest '] = $ row ['count (TempID)'];
}
Disconnect ($ conn );
Return $ olnum; // from www.w3sky.com
}
The connect (), disconnect (), query (), and fetch_array () functions are in dbmanager. inc. PHP.
Dbmanager. inc. PHP
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.