<?php
/****************************************
* Mini AJAX Chatroom By Longbill
* http://www.longbill.cn
* Longbill all rights reserved
* 2008-03-26
创作共用(Creative Commons)
你可以免费:
* 拷贝、分发、呈现和表演当前作品
* 制作派生作品
但是必须基于以下条款:
* 署名。你必须明确标明作者的名字。.
* 非商业用途。 你不可将当前作品用于商业目的。
* 保持一致。 如果你基于当前作品更改、变换或构造新作品,你应当按照与当前协议完全相同的协议分发最终作品
* 对于任何二次使用或分发,你必须让其他人明确当前作品的授权条款
* 在得到作者的明确允许下,这里的某些条款可以放弃
此约定是法律文本 (完整的协议)的简单易读概要
****************************************/
//****************参数设置****************
//显示在线用户
$disonline = true;
//新登陆时显示最近内容的条数(默认为30条)
$leastnum = 30;
//默认的房间名(默认是每天换一个文件),如果去掉d,则是每月换一个文件
$room = date("Y-m-d");
//房间保存路径,必须以/结尾
$roomdir = "rooms/";
//编码方式
$charset = "UTF-8";
//客户端最大显示内容条数(建议不要太大)
$maxdisplay = 300;
//语言
$lang = array(
//聊天室描述
"description"=>"欢迎来到迷你AJAX聊天室。最新版本 1.2。下载请到<a href='http://longbill.cn' target=_blank>www.longbill.cn</a>",
//聊天室标题
"title"=>"Mini AJAX Chatroom By Longbill",
//第一个到聊天室的欢迎
"firstone"=>"<span style='color:#16a5e9;'>Welcome to Longbill's Mini AJAX Chatroom!</span>",
//当信息有禁止内容时显示
"ban"=>"I am a pig!",
//关键字
"keywords"=>"聊天室,迷你,小型,AJAX,Chat,Chatroom,Longbill,Longbill.cn,PHP,Javascript",
//发言提示
"hereyourwords" => "在这里发言!"
);
header("content-type:text/html; charset=utf-8");
$get_past_sec = 3; //如果发现丢话,可以适当调大这个值
$touchs = 10; //检查在线人数的时间间隔
$title = $lang["title"];
$earlier = 10;
$description = $lang["description"];
$origroom = $room;
$least = ($_GET["dis"])?intval($_GET["dis"]):$leastnum;
$touchme = $_POST['touchme'];
if (!is_dir($roomdir)) @mkdir($roomdir) or die("error when creating folder $roomdir");
$room = $_GET['room'];
if (!$room) $room = $_POST["room"];
$room = checkfilename($room);
if (!$room) $room = $origroom;
$filename = $roomdir.$room.".dat.php";
$datafile = $roomdir.$room.".php";
if (!file_exists($filename)) @file_put_contents($filename,'<?php die();?>'."\n".time()."|".$lang["firstone"]."\n");
if (!file_exists($datafile)) @file_put_contents($datafile,'<?php die();?>'."\n");
$action = $_POST["action"];
if (!function_exists("file_get_contents"))
{
function file_get_contents($path)
{
if (!file_exists($path)) return false;
$fp=@fopen($path,"r");
$all=fread($fp,filesize($path));
fclose($fp);
return $all;
}
}
if (!function_exists("file_put_contents"))
{
function file_put_contents($path,$val)
{
$fp=@fopen($path,"w");
fputs($fp,$val);
fclose($fp);
return true;
}
}
function checkfilename($file)
{
if (!$file) return "";
$file = trim($file);
$a = substr($file,-1);
$file = eregi_replace("^[.\\\/]*","",$file);
$file = eregi_replace("[.\\\/]*$","",$file);
$arr = array("../","./","/","\\","..\\",".\\");
$file = str_replace($arr,"",$file);
return $file;
}
function get_ip()
{
global $_SERVER;
if ($_SERVER)
{
if ( $_SERVER[HTTP_X_FORWARDED_FOR] )
$realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if ( $_SERVER["HTTP_CLIENT_ip"] )
$realip = $_SERVER["HTTP_CLIENT_ip"];
else
$realip = $_SERVER["REMOTE_ADDR"];
}
else
{
if ( getenv( 'HTTP_X_FORWARDED_FOR' ) )
$realip = getenv( 'HTTP_X_FORWARDED_FOR' );
else if ( getenv( 'HTTP_CLIENT_ip' ) )
$realip = getenv( 'HTTP_CLIENT_ip' );
else
$realip = getenv( 'REMOTE_ADDR' );
}
return $realip;
}
function array2json($arr)
{
$keys = array_keys($arr);
$isarr = true;
$json = "";
for($i=0;$i<count($keys);$i++)
{
if ($keys[$i] !== $i)
{
$isarr = false;
break;
}
}
$json = $space;
$json.= ($isarr)?"[":"{";
for($i=0;$i<count($keys);$i++)
{
if ($i!=0) $json.= ",";
$item = $arr[$keys[$i]];
$json.=($isarr)?"":$keys[$i].':';
if (is_array($item))
$json.=array2json($item);
else if (is_string($item))
$json.='"'.str_replace(array("\r","\n"),"",$item).'"';
else $json.=$item;
}
$json.= ($isarr)?"]":"}";
return $json;
}
function keeponline()
{
global $disonline,$datafile;
if (!$disonline) return;
$name = $_POST['name'];
$ip = get_ip();
$onlines = @file_get_contents($datafile);
$s1 = "|{$name}|{$ip}|";
if (strpos($onlines,$s1) === false)
{
if (strpos($onlines,"|".$name."|") === false)
{
$fp = @fopen($datafile,"a+");
if ($fp)
{
if (@flock($fp, LOCK_EX))
{
@fputs($fp,time()."|".time().$s1."\n");
@flock($fp, LOCK_UN);
}
@fclose($fp);
}
}
else
{
echo "NAME";
die();
}
}
}
if ($action == "write")
{
$color = $_POST["color"];
if (!eregi("[0-9a-fA-F]{6}",$color) || $color == "#000000") $color = "";
$color = "#".$color;
$size = intval($_POST["size"]);
$name = str_replace(array("\n","\r"),"",$_POST['name']);
if (!$name) die("No Name!!");
$ip = get_ip();
keeponline();
$s = "";
$style = "";
$font = $_POST["font"];
if ($font == "songti") $font = "宋体";
else if ($font == "heiti") $font = "黑体";
else if ($font == "kaiti") $font = "楷体_GB2312";
else $font = "";
$style .= (!$font)?"":"font-family:".$font.";";
$style .= (!$_POST["bold"])?"":"font-weight:bold;";
$style .= (!$color || $color == "#")?"":"color:{$color};";
$style .= (!$size || $size == "16")?"":"font-size:{$size}px;";
$t = time();
$arr = explode("\n",$_POST['content']);
for($i = 0;$i<count($arr);$i++)
{
$content = $arr[$i];
$content = trim($content);
$content = str_replace(array("\n","\r"),"",$content);
if (!$content) continue;
$content = htmlspecialchars($content);
$content = preg_replace("~\[img\](http:\/\/[a-zA-Z0-9\.-_\+%\?]*)\[\/img\]~i", "<img src='$1' />", $content);
$content = ($style)?"<span style='{$style}'>{$content}</span>":$content;
$s.= $t."|".$name.":".$content."\n";
}
if (!$s) die("No Content!!");
$fp = @fopen($filename,"a+");
if (!$fp) die("repeat");
$re_time = 0;
while(!@flock($fp, LOCK_EX))
{
sleep(1);
$re_time++;
if ($re_time >=4) break;
}
if ($re_time <4)
{
@fputs($fp,$s);
@flock($fp, LOCK_UN);
}
else die("repeat");
@fclose($fp);
echo "OK";
}
else if ($action == "read")
{
$first = $_POST["first"];
$lastmod = intval($_POST["lastmod"]) - $get_past_sec; //得到两秒以内的所有发言,
$alastmod = @filemtime($filename);
$name = $_POST['name'];
$name = str_replace("\n","",$name);
$ip = get_ip();
$json = array();
$json["lastmod"] = time();
$item = array();
$newonline = array();
$offline = array();
$fp = @fopen($filename,'r');
flock($fp,LOCK_EX);
$s = fread($fp,filesize($filename));
flock($fp,LOCK_UN);
fclose($fp);
$lines = explode("\n",$s);
if ($alastmod >= $lastmod && !$first)
{
foreach($lines as $l)
{
$item2 = array();
$l = str_replace(array("\n","\r"),"",$l);
if (strpos($l,"|") === false) continue;
$arr = explode("|",$l);
$t = intval($arr[0]);
if ($t >= $lastmod)
{
$item2["time"] = date("H:i:s",$t);
$item2["word"] = addslashes($arr[1]);
$item[] = $item2;
}
}
}
else if ($first)
{
$item = array();
$total = count($lines);
for($i=$total-1;$i>=$total-$least;$i--)
{
if ($i<=0) break;
$item2 = array();
$l = str_replace(array(
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源内容:项目全套源码+完整文档 源码说明: 全部项目源码都是经过测试校正后百分百成功运行。 SpringBoot 毕业设计,SpringBoot 课程设计,基于SpringBoot+Vue开发的,含有代码注释,新手也可看懂。ssm整合开发,小程序毕业设计、期末大作业、课程设计、高分必看,下载下来,简单部署,就可以使用。 包含:项目源码、数据库脚本、软件工具等,该项目可以作为毕设、课程设计使用,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 项目都经过严格调试,确保可以运行! 1. 技术组成 前端:Vue/JSP/React/HTML+JS+CSS/ASP 后台框架代码:java/c/c++/php/VB/lun/Andorid/Python 开发环境:idea 数据库:MySql(建议用 5.7,8.0 有时候会有坑) 部署环境:Tomcat(建议用 7.x 或者 8.x b版本),maven Spring root vue.js
资源推荐
资源详情
资源评论
收起资源包目录
【php+mysql+毕业设计源代码】MiniAJAX聊天室程序beta_miniajaxchatroom.rar (1个子文件)
【php+mysql+毕业设计源代码】MiniAJAX聊天室程序 v1.2 beta_miniajaxchatroom
[聊天留言]MiniAJAX聊天室程序 v1.2 beta_miniajaxchatroom
chat.php 23KB
共 1 条
- 1
资源评论
程序员小马软件开发定制
- 粉丝: 4753
- 资源: 2247
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功