Session Statistics Online Number

Source: Internet
Author: User

/*
* When no verification code is involved
*/

Count the number of visitors (not logged in)

$map = Array (' Session_expire ' =>array (' GT ', now_time), ' Session_data ' =>array (' eq ', ') '); $youke = D (' Session ')- >where ($map)->count ();d UMP ($youke);


Count members (logged in)

$map = Array (' Session_expire ' =>array (' GT ', now_time), ' Session_data ' =>array (' neq ', ') '); $huiyuan = D (' session ') ->where ($map)->count ();d UMP ($huiyuan);

Total number of online statistics

$map = Array (' Session_expire ' =>array (' GT '), now_time), $inline = D (' session ')->where ($map)->count ();d UMP ($ inline);



Add the SessionID field to the user table, log the login SessionID, and determine if a user is online

$session _id = session_id (), $map = Array (' session_id ' = $session _id, ' Session_expire ' =>array (' GT ', now_time), ' Session_data ' =>array (' neq ', ')); $res = D (' Session ')->where ($map)->find (); if ($res) dump (' The user is online. '); else dump (' The user is not on the line. ‘);


The verification code will also be stored in the session, so when we judge it, we cannot count the value of the record.
You need to get the value of the data first, and then determine if there is no user information stored in the parameter name. Although the Session_data field is stored in binary, the query is a string.
Session (' user ', $data);//User login information
Get real number of members
Query the session record with value

$list = D (' Session ')->where (Array (' Session_data ' =>array (' NEQ ', '), ' Session_expire ' =>array (' GT ', Now_time ))->select ();d UMP ($list);//Determine if there is a member ID $count=0;foreach ($list as $k = $value) {if (Strpos ($value [' Session_ Data '], ' user ') {$count + +;}} Dump ($count);//true number of members

  

Session Statistics Online Number

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.