Home Backend Development PHP Tutorial 怎样实现在线用户列表?_PHP

怎样实现在线用户列表?_PHP

Jun 01, 2016 pm 12:34 PM
online accomplish how user

PHP代码:
<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">//更新的頻率---秒数<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">//如果用戶已經登入了<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">//查詢在線到表是否已經有用戶的名稱<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">//查詢的結果<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">//如果用戶已經在在線列表了<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">//如果用戶已經不在在線列表<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">//查詢在線到表是否已經有訪客的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">//查詢的結果<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地址已經在在線列表了<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秒內沒有動作的用戶<br><br></font><font color="#0000bb">?><br><br></font><br><br></font></font>
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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 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 implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

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

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

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

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

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

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 PHP Game Requirements Implementation Guide Mar 11, 2024 am 08:45 AM

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

See all articles