Home Backend Development PHP Tutorial [分享] 《魔镜在线》一个在线随机聊天网站源码,该如何处理

[分享] 《魔镜在线》一个在线随机聊天网站源码,该如何处理

Jun 13, 2016 am 10:04 AM
gt session set update

[分享] 《魔镜在线》一个在线随机聊天网站源码
程序使用PHP+MySQL,jQuery实现Ajax,页面布局用的DIV+CSS,并有一个VB写的客户端程序。

原演示地址:http://ask.n9sky.com/MagicMirror/ (现在不能访问了)

现在贴出部分代码:

server.php 主要的操作处理都在这个文件

PHP code
 <br>  <?php <br /> $do = @$_GET['do']; <br> if ('' == $do) <br> { <br> 	exit('Missing Action'); <br> } <br> require 'config.php'; <br> require 'dll.php'; <br> session_start(); <br> // check session <br> if ('' == $_SESSION['sid']) exit('登录超时,请关闭重试!'); <br> switch ($do) <br> { <br> 	case 'init': <br> 		// check user && update <br> 		dll::import('mysql'); <br> 		$db = new mysql(); <br> 		$db->connect($dbs['server'], $dbs['user'], $dbs['password']); <br> 		$db->database($dbs['database']); <br> 		// update <br> 		$rs = $db->update(DBPrefix.'user', 'sid="'.$_SESSION['sid'].'"'); <br> 		$rs->set('client_to', ''); <br> 		$rs->set('role', RoleOnline); <br> 		$rs->set('last_access_time', time()); <br> 		$rs->setfunc('login_count', 'login_count+1'); <br> 		$rs->set('last_login_time', time()); <br> 		$ip = $_SERVER['REMOTE_ADDR']; <br> 		$ipx = explode('.', $ip); <br> 		$iplong =  <br> 			$ipx[0] * 16777216 + <br> 			$ipx[1] * 65536 + <br> 			$ipx[2] * 256 + <br> 			$ipx[3]; <br> 		$rs->set('last_login_ip', $iplong); <br> 		if (!$rs->update()) <br> 		{ <br> 			// add new <br> 			$rs = $db->insert(DBPrefix.'user'); <br> 			$rs->set('sid', $_SESSION['sid']); <br> 			$rs->set('client_to', ''); <br> 			$rs->set('role', RoleOnline); <br> 			$rs->set('last_access_time', time()); <br> 			$rs->set('login_count', 1); <br> 			$rs->set('last_login_time', time()); <br> 			$rs->set('last_login_ip', $iplong); <br> 			$rs->insert(); <br> 		} <br> 		$db->close(); <br> 		// display init page <br> 		display('init.html'); <br> 	break; <br> 	case 'status': <br> 		dll::import('mysql'); <br> 		// access $dbs <br> 		global $dbs; <br> 		$db = new mysql(); <br> 		$db->connect($dbs['server'], $dbs['user'], $dbs['password']); <br> 		$db->database($dbs['database']); <br> 		// update access <br> 		update_access($db); <br> 		// import mysql.class <br> 		display('server.status.html'); <br> 		$db->close(); <br> 	break; <br> 	case 'work': <br> 		$mode = $_GET['mode']; <br> 		// update work mode <br> 		dll::import('mysql'); <br> 		$db = new mysql(); <br> 		$db->connect($dbs['server'], $dbs['user'], $dbs['password']); <br> 		$db->database($dbs['database']); <br> 		// update <br> 		$rs = $db->update(DBPrefix.'user', 'sid="'.$_SESSION['sid'].'"'); <br> 		switch ($mode) <br> 		{ <br> 			case 'answer': <br> 				$rs->set('role', RoleAnswer); <br> 			break; <br> 			case 'asker': <br> 				$rs->set('role', RoleAsker); <br> 			break; <br> 			case 'chater': <br> 				$rs->set('role', RoleChater); <br> 			break; <br> 			case 'offline': <br> 				$rs->set('role', RoleOffline); <br> 				$rs->set('client_to', ''); <br> 				// delete input status cache <br> 				@unlink(dirname('.').'/cache/'.$_SESSION['sid'].'.input.status'); <br> 				// clear session <br> 				unset($_SESSION); <br> 			break; <br> 		} <br> 		$rs->set('last_access_time', time()); <br> 		$rs->update(); <br> 		$db->close(); <br> 		// display mode page <br> 		if ($mode != 'offline') <br> 		{<div class="clear">
                 
              
              
        
            </div>
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 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)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Detailed explanation of the Set tag function in MyBatis dynamic SQL tags Feb 26, 2024 pm 07:48 PM

Interpretation of MyBatis dynamic SQL tags: Detailed explanation of Set tag usage MyBatis is an excellent persistence layer framework. It provides a wealth of dynamic SQL tags and can flexibly construct database operation statements. Among them, the Set tag is used to generate the SET clause in the UPDATE statement, which is very commonly used in update operations. This article will explain in detail the usage of the Set tag in MyBatis and demonstrate its functionality through specific code examples. What is Set tag Set tag is used in MyBati

How to solve session failure How to solve session failure Oct 18, 2023 pm 05:19 PM

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to PHP Session cross-domain problem Solution to PHP Session cross-domain problem Oct 12, 2023 pm 03:00 PM

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

How to implement SMS login in Redis shared session application How to implement SMS login in Redis shared session application Jun 03, 2023 pm 03:11 PM

1. Implementing SMS login based on session 1.1 SMS login flow chart 1.2 Implementing sending SMS verification code Front-end request description: Description of request method POST request path /user/code request parameter phone (phone number) return value No back-end interface implementation: @Slf4j@ ServicepublicclassUserServiceImplextendsServiceImplimplementsIUserService{@OverridepublicResultsendCode(Stringphone,HttpSessionsession){//1. Verify mobile phone number if

KDE Plasma 6.1 brings many enhancements to the popular Linux desktop KDE Plasma 6.1 brings many enhancements to the popular Linux desktop Jun 23, 2024 am 07:54 AM

After several pre-releases, the KDE Plasma development team unveiled version 6.0 of its desktop environment for Linux and BSD systems on 28 February, using the Qt6 framework for the first time. KDE Plasma 6.1 now comes with a number of new features t

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

What are the differences between JavaScript and PHP cookies? What are the differences between JavaScript and PHP cookies? Sep 02, 2023 pm 12:29 PM

JavaScriptCookies Using JavaScript cookies is the most effective way to remember and track preferences, purchases, commissions and other information. Information needed for a better visitor experience or website statistics. PHPCookieCookies are text files that are stored on client computers and retained for tracking purposes. PHP transparently supports HTTP cookies. How do JavaScript cookies work? Your server sends some data to your visitor's browser in the form of a cookie. Browsers can accept cookies. If present, it will be stored on the visitor's hard drive as a plain text record. Now, when a visitor reaches another page on the site

See all articles