Home Backend Development PHP Tutorial php判断在线用户实例详解

php判断在线用户实例详解

Apr 18, 2017 pm 03:37 PM
judgment online user

怎么才能准确的判断用户是否在线呢?下面小编就来给大家分享一个实例。

解决了昨天的问题:表结果变了一下,如下:

CREATE TABLE TB_User (       --用户表
N_UserId   Number(5)      NOT NULL,       --用户ID
V_NickName  VARCHAR2(10)  NOT NULL,       --昵   称
V_PWD      VARCHAR2(10)  NOT NULL,        --密   码
V_TrueName  VARCHAR2(20),                 --姓   名
Primary Key (N_UserId)
)
CREATE TABLE TB_OnlineUser ( --在线用户
N_OnlineUserId Number(5)      NOT NULL,   --在线用户ID
     D_LoginTime   Number (16),       --登陆时间以秒计
     N_OnlineID    Number(5),   --与onlineusercount相关联。
    Primary Key (N_OnlineID)
)
/
CREATE TABLE TB_OnlineUserCount (  --在线用户统计表
N_OnlineID    Number(5)      NOT NULL,   --系统ID号
N_OnlineUserId Number(5)      NOT NULL,   --在线用户ID
D_LoginDate    Date                   ,          --登陆日期
D_LoginTime   Number (16)    ,    --登陆时间以秒计
D_OverDate      Date    ,          --结束日期 
D_OverTime    Number (16)             ,    --结束时间
     Primary Key (N_OnlineID)
)
/
/*---LoginselectNew.php---该程序是登陆检查程序----*/
<? 
session_start();
Copy after login

/*思路:首先用户登陆,判断是否有该用户,判断是否密码通过,否则返回参数进行特殊处理。(登陆不成功)
登陆成功后,如果该用户不在线(一般不在线,特殊情况如果他用另一台机器打开浏览器重新再登陆,那么他有可能在线),
先进行session变量注册,取得相应条件向1.统计表与2.在线表中插数据。进入到登陆页。
如果用户在线:先取得在线用户的系统ID,因为在备份该用户离开时有用。接着删除该在线用户.接着进行该用户离开时间的备份.
*/

session_register("objsNickName");
require(&#39;oracle8conn.php&#39;);
$name=trim($name);
$pwd=trim($pwd);
ob_start();      //缓冲输出

 $stmtNick = OCIParse($conn,"select count(*) countnickname from tb_user where v_nickname=&#39;$name&#39;"); 

 OCIExecute($stmtNick);
   while(OCIFetchInto($stmtNick,&$arrN)){
     if ($arrN[0]==0){
           Header("Location:Logintest.php?Msg=1");
     }else{
           //用户名通过
           unset($arrNickName);           //撤消临时数组
           $stmtPwd = OCIParse($conn,"select count(*) countpwd from tb_user where v_pwd=&#39;$pwd&#39; and v_nickname=&#39;$name&#39;"); 
           OCIExecute($stmtPwd);
            while(OCIFetchInto($stmtPwd,&$arrP,OCI_NUM)){
              if ($arrP[0]==0){
                 Header("Location:Logintest.php?Msg=2");
            }else{//密码通过
    //取出用户的ID号
       $stmtUid = OCIParse($conn,"select n_userID from tb_user where v_nickname=&#39;$name&#39;"); 
       OCIExecute($stmtUid);
       while(OCIFetchInto($stmtUid,&$arrU,OCI_NUM)){
            $intOnlineUserID=$arrU[0];          
       }//while_Over    
    //如果该用户通过另一个浏览器重复登陆,解决如下 
       $stmOnlineFlag=OCIParse($conn,"select count(*) from tb_onlineuser where N_ONLINEUSERID=&#39;$intOnlineUserID&#39;");
       OCIExecute($stmOnlineFlag);     
       while(OCIFetchInto($stmOnlineFlag,&$arronlineFlag,OCI_NUM)){
              if ($arronlineFlag[0]!=0){                               //表示已经在线
                                                                      //先取到在线用户关联系统ID
                  $stmtSysID= OCIParse($conn,"select N_ONLINEID from tb_onlineuser where N_ONLINEUSERID=&#39;$intOnlineUserID&#39;"); 
                  OCIExecute($stmtSysID);
                  while(OCIFetchInto($stmtSysID,&$arrSysID,OCI_NUM)){
                      $SysID=$arrSysID[0];          
                   }//while_Over                                     //找完后踢出该用户 
                  $stmt = OCIParse($conn, "delete from tb_onlineuser where N_ONLINEUSERID=&#39;$intOnlineUserID&#39;");
                  OCIExecute($stmt);
                  print "删除成功";                                  //最后作记录备份
                  $tmpTime=time(); //结束时间
                  $DatLoginDate = date( "Y-m-d");//结束日期
                  $DatLoginDate = "to_date(&#39;".$DatLoginDate."&#39;,&#39;YY/MM/DD&#39;)";
                  $stmtUserCount = OCIParse($conn, "update tb_onlineusercount set D_OverDate=$DatLoginDate ,D_OverTime=$tmpTime where N_OnlineID=&#39;$SysID&#39;");//条件是相关联的系统ID 
                  OCIExecute($stmtUserCount);
                  print "添加成功到统计表中。";
                }//endif                                              //不在线正常注册
       $objsNickName=$name; //注册Session变量
       unset($arrPwd);             //撤消临时数组
       srand((double)microtime()*1000000000);
       $intOnlineID = rand();              //取一个系统ID号
       $DatLoginDate = date( "Y-m-d");    //取得系统日期存入到Online表中去。
       $DatLogintime = time();           //取系统时间
       $DatLoginDate = "to_date(&#39;".$DatLoginDate."&#39;,&#39;YY/MM/DD&#39;)";    
       $stmt = OCIParse($conn, "insert into tb_onlineuser (N_OnlineUserId,D_LoginTime,N_OnlineID) values ($intOnlineUserID,$DatLogintime,$intOnlineID)");
       OCIExecute($stmt);
       $stmtC = OCIParse($conn, "insert into TB_OnlineUserCount (N_OnlineID,N_OnlineUserId,D_LoginDate,D_LoginTime) values ($intOnlineID,$intOnlineUserID,$DatLoginDate,$DatLogintime)");
       OCIExecute($stmtC);
       Header("Location:index.php");  //成功登陆!
          }//whileOVER
        }//end if
      }//while_Over 
    }//end if
}//while_Over
?>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Xiaohongshu account to find users? Can I find my mobile phone number? How to use Xiaohongshu account to find users? Can I find my mobile phone number? Mar 22, 2024 am 08:40 AM

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the &quot;Discover&quot; button in the lower right corner, and then select the &quot;Notes&quot; option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the &quot;Follow&quot; button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select &quot;Personal Information&quot;

Log in to Ubuntu as superuser Log in to Ubuntu as superuser Mar 20, 2024 am 10:55 AM

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

How to develop an online restaurant reservation system using Laravel How to develop an online restaurant reservation system using Laravel Nov 02, 2023 pm 01:48 PM

How to use Laravel to develop an online restaurant reservation system In recent years, with the rapid development of the Internet and mobile Internet, online reservations have become an indispensable part of modern people's lives. The catering industry is no exception. More and more restaurants are beginning to provide online reservation services to improve user experience and expand market share. This article will introduce how to use the Laravel framework to develop a simple but fully functional online restaurant reservation system, and provide specific code examples to facilitate readers to learn and practice. Environment setup First, we need

Tutorial: How to delete a normal user account in Ubuntu system? Tutorial: How to delete a normal user account in Ubuntu system? Jan 02, 2024 pm 12:34 PM

Many users have been added to the Ubuntu system. I want to delete the users that are no longer in use. How to delete them? Let’s take a look at the detailed tutorial below. 1. Open the terminal command line and use the userdel command to delete the specified user. Be sure to add the sudo permission command, as shown in the figure below. 2. When deleting, be sure to be in the administrator directory. Ordinary users do not have this permission. , as shown in the figure below 3. After the delete command is executed, how to judge whether it has been truly deleted? Next we use the cat command to open the passwd file, as shown in the figure below 4. We see that the deleted user information is no longer in the passwd file, which proves that the user has been deleted, as shown in the figure below 5. Then we enter the home file

What is sudo and why is it important? What is sudo and why is it important? Feb 21, 2024 pm 07:01 PM

sudo (superuser execution) is a key command in Linux and Unix systems that allows ordinary users to run specific commands with root privileges. The function of sudo is mainly reflected in the following aspects: Providing permission control: sudo achieves strict control over system resources and sensitive operations by authorizing users to temporarily obtain superuser permissions. Ordinary users can only obtain temporary privileges through sudo when needed, and do not need to log in as superuser all the time. Improved security: By using sudo, you can avoid using the root account during routine operations. Using the root account for all operations may lead to unexpected system damage, as any mistaken or careless operation will have full permissions. and

Analysis of user password storage mechanism in Linux system Analysis of user password storage mechanism in Linux system Mar 20, 2024 pm 04:27 PM

Analysis of user password storage mechanism in Linux system In Linux system, the storage of user password is one of the very important security mechanisms. This article will analyze the storage mechanism of user passwords in Linux systems, including the encrypted storage of passwords, the password verification process, and how to securely manage user passwords. At the same time, specific code examples will be used to demonstrate the actual operation process of password storage. 1. Encrypted storage of passwords In Linux systems, user passwords are not stored in the system in plain text, but are encrypted and stored. L

How to use Java Websocket to implement online audio and video calls? How to use Java Websocket to implement online audio and video calls? Dec 02, 2023 am 09:44 AM

How to use JavaWebsocket to implement online audio and video calls? In today's digital age, real-time communication is becoming more and more common. Whether it is remote collaboration at work or remote communication with relatives and friends at home, real-time audio and video calls have become an indispensable part of people. This article will introduce how to use JavaWebsocket to implement online audio and video calls, and provide specific code examples. 1. Understand WebsocketWebsocket is a new technology in HTML5

Oracle Database: Can one user have multiple tablespaces? Oracle Database: Can one user have multiple tablespaces? Mar 03, 2024 am 09:24 AM

Oracle database is a commonly used relational database management system, and many users will encounter problems with the use of table spaces. In Oracle database, a user can have multiple table spaces, which can better manage data storage and organization. This article will explore how a user can have multiple table spaces in an Oracle database and provide specific code examples. In Oracle database, table space is a logical structure used to store objects such as tables, indexes, and views. Every database has at least one tablespace,

See all articles