[分享] 《魔镜在线》一个在线随机聊天网站源码
程序使用PHP+MySQL,jQuery实现Ajax,页面布局用的DIV+CSS,并有一个VB写的客户端程序。
原演示地址:http://ask.n9sky.com/MagicMirror/ (现在不能访问了)
现在贴出部分代码:
server.php 主要的操作处理都在这个文件
<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>