怎樣實現(xiàn)在線用戶列表?_PHP
Jun 01, 2016 pm 12:34 PM<font color="#000000"><br><br><br><font color="#0000bb"><br><br></font><font color="#ff8000">#<br><br># Author: Marco(hkfuk)<br><br>#<br><br># Contact: Crazy_Marco@msn.com<br><br>#<br><br></font><font color="#0000bb">$host</font><font color="#007700">=</font><font color="#dd0000">"localhost"</font><font color="#007700">;</font><font color="#ff8000">//mysql的host<br><br></font><font color="#0000bb">$user</font><font color="#007700">=</font><font color="#dd0000">"root"</font><font color="#007700">;</font><font color="#ff8000">//mysql的用戶名稱<br><br></font><font color="#0000bb">$pw</font><font color="#007700">=</font><font color="#dd0000">""</font><font color="#007700">;</font><font color="#ff8000">//mysql的密碼<br><br></font><font color="#0000bb">$db</font><font color="#007700">=</font><font color="#dd0000">""</font><font color="#007700">;</font><font color="#ff8000">//mysql資料庫名稱<br><br></font><font color="#0000bb">$update_time</font><font color="#007700">=</font><font color="#dd0000">"30"</font><font color="#007700">;</font><font color="#ff8000">//更新的頻率---秒數(shù)<br><br></font><font color="#0000bb">session_start</font><font color="#007700">();<br><br>if(!</font><font color="#0000bb">$_SESSION</font><font color="#007700">[</font><font color="#dd0000">'name'</font><font color="#007700">])</font><font color="#0000bb">session_register</font><font color="#007700">(</font><font color="#dd0000">"name"</font><font color="#007700">);<br><br></font><font color="#ff8000">############################################<br><br></font><font color="#0000bb">$con</font><font color="#007700">=</font><font color="#0000bb">mysql_connect</font><font color="#007700">(</font><font color="#0000bb">$host</font><font color="#007700">,</font><font color="#0000bb">$user</font><font color="#007700">,</font><font color="#0000bb">$pw</font><font color="#007700">)or die(</font><font color="#dd0000">"不可以連接資料庫"</font><font color="#007700">);<br><br></font><font color="#0000bb">$now</font><font color="#007700">=</font><font color="#0000bb">time</font><font color="#007700">();<br><br></font><font color="#0000bb">mysql_select_db</font><font color="#007700">(</font><font color="#0000bb">$db</font><font color="#007700">,</font><font color="#0000bb">$con</font><font color="#007700">)or die(</font><font color="#dd0000">"錯誤的資料庫$db"</font><font color="#007700">);<br><br>if(!empty(</font><font color="#0000bb">$name</font><font color="#007700">)){</font><font color="#ff8000">//如果用戶已經(jīng)登入了<br><br></font><font color="#0000bb">$query</font><font color="#007700">=</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#dd0000">"select count(username) from online_list where username='$name'"</font><font color="#007700">,</font><font color="#0000bb">$con</font><font color="#007700">);</font><font color="#ff8000">//查詢在線到表是否已經(jīng)有用戶的名稱<br><br></font><font color="#0000bb">$result</font><font color="#007700">=</font><font color="#0000bb">mysql_result</font><font color="#007700">(</font><font color="#0000bb">$query</font><font color="#007700">,</font><font color="#0000bb">0</font><font color="#007700">);</font><font color="#ff8000">//查詢的結(jié)果<br><br></font><font color="#007700">if(</font><font color="#0000bb">$result</font><font color="#007700">!=</font><font color="#0000bb">0</font><font color="#007700">){</font><font color="#ff8000">//如果用戶已經(jīng)在在線列表了<br><br></font><font color="#007700">@</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#dd0000">"update online_list set second_time='$now' where username='$name'"</font><font color="#007700">,</font><font color="#0000bb">$con</font><font color="#007700">);</font><font color="#ff8000">//更新用戶的最後在線時間<br><br></font><font color="#007700">}else{</font><font color="#ff8000">//如果用戶已經(jīng)不在在線列表<br><br></font><font color="#007700">@</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#dd0000">"insert into online_list(username,userip,online_time,second_time)values('$name','$REMOTE_ADDR','$now','$now')"</font><font color="#007700">,</font><font color="#0000bb">$con</font><font color="#007700">);</font><font color="#ff8000">//新增一個用戶到在線列表<br><br></font><font color="#007700">}<br><br>}<br><br><br><br>else{</font><font color="#ff8000">//如果用戶沒有登入<br><br></font><font color="#0000bb">$query</font><font color="#007700">=</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#dd0000">"select count(userip) from online_list where userip='$REMOTE_ADDR'"</font><font color="#007700">,</font><font color="#0000bb">$con</font><font color="#007700">);</font><font color="#ff8000">//查詢在線到表是否已經(jīng)有訪客的ip 地址<br><br></font><font color="#0000bb">$result</font><font color="#007700">=</font><font color="#0000bb">mysql_result</font><font color="#007700">(</font><font color="#0000bb">$query</font><font color="#007700">,</font><font color="#0000bb">0</font><font color="#007700">);</font><font color="#ff8000">//查詢的結(jié)果<br><br></font><font color="#007700">if(</font><font color="#0000bb">$result</font><font color="#007700">!=</font><font color="#0000bb">0</font><font color="#007700">){</font><font color="#ff8000">//如果訪客的ip地址已經(jīng)在在線列表了<br><br></font><font color="#007700">@</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#dd0000">"update online_list set second_time='$now' where userip='$REMOTE_ADDR'"</font><font color="#007700">,</font><font color="#0000bb">$con</font><font color="#007700">);</font><font color="#ff8000">//更新訪客的最後在線時間<br><br></font><font color="#007700">}else{</font><font color="#ff8000">//如果用戶列表沒有訪客的ip地址<br><br></font><font color="#007700">@</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#dd0000">"insert into online_list(username,userip,online_time,second_time)values('訪客','$REMOTE_ADDR','$now','$now')"</font><font color="#007700">,</font><font color="#0000bb">$con</font><font color="#007700">);</font><font color="#ff8000">//新增一個訪客到在線列表<br><br></font><font color="#007700">}<br><br>}<br><br></font><font color="#0000bb">$del_time</font><font color="#007700">=</font><font color="#0000bb">$now</font><font color="#007700">-</font><font color="#0000bb">$update_time</font><font color="#007700">;<br><br>@</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#dd0000">"delete from online_list where second_time<font color="#007700">,</font><font color="#0000bb">$con</font><font color="#007700">);</font><font color="#ff8000">//刪除在$update_time秒內(nèi)沒有動作的用戶<br><br></font><font color="#0000bb">?><br><br></font><br><br></font></font>

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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 "Discover" button in the lower right corner, and then select the "Notes" 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 "Follow" 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 "Personal Information"

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 implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

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

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

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,
