首页 > 开发 > PHP > 正文

ajax php 聊天室实例代码(1)

2024-05-04 23:06:13
字体:大 中 小
来源:转载
供稿:网友
  1. <?php 
  2. /* 
  3. ajax php 聊天室实例代码 
  4. 但是必须基于以下条款: 
  5.   * 署名。你必须明确标明作者的名字。. 
  6.   * 非商业用途。 你不可将当前作品用于商业目的。 
  7.   * 保持一致。 如果你基于当前作品更改、变换或构造新作品,你应当按照与当前协议完全相同的协议分发最终作品 
  8.   * 对于任何二次使用或分发,你必须让其他人明确当前作品的授权条款 
  9.   * 在得到作者的明确允许下,这里的某些条款可以放弃 
  10. 此约定是法律文本 (完整的协议)的简单易读概要  
  11. ****************************************/ 
  12. //****************参数设置**************** 
  13. //显示在线用户 
  14. $disonline = true; 
  15. //新登陆时显示最近内容的条数(默认为30条) 
  16. $leastnum = 30; 
  17. //默认的房间名(默认是每天换一个文件),如果去掉d,则是每月换一个文件 
  18. $room = date("y-m-d"); 
  19. //房间保存路径,必须以/结尾 
  20. $roomdir = "rooms/"; 
  21. //编码方式 
  22. $charset = "utf-8";  
  23. //客户端最大显示内容条数(建议不要太大) 
  24. $maxdisplay = 300; 
  25.  
  26. //语言 
  27. $lang = array( 
  28. //聊天室描述 
  29. "description"=>"欢迎来到迷你ajax聊天室。最新版本 1.2。下载请到<a href='http://111cn.net' target=_blank>www.111cn.net</a>",  
  30. //聊天室标题 
  31. "title"=>"mini ajax chatroom by longbill",  
  32. //第一个到聊天室的欢迎 
  33. "firstone"=>"<span style='color:#16a5e9;'>welcome to longbill's mini ajax chatroom!</span>",  
  34. //当信息有禁止内容时显示 
  35. "ban"=>"i am a pig!", 
  36. //关键字 
  37. "keywords"=>"聊天室,迷你,小型,ajax,chat,chatroom,longbill,111cn.net,php,网页特效", 
  38. //发言提示 
  39. "hereyourwords" => "在这里发言!" 
  40. ); 
  41. error_reporting(e_all ^ e_notice ^ e_warning); 
  42. header("content-type:text/html; charset=utf-8"); 
  43. $get_past_sec = 3; //如果发现丢话,可以适当调大这个值 
  44. $touchs = 10; //检查在线人数的时间间隔 
  45.   
  46. if (!function_exists("file_get_contents")) 
  47. { 
  48.  function file_get_contents($path) 
  49.  { 
  50.   if (!file_exists($path)) return false; 
  51.   $fp=@fopen($path,"r"); 
  52.   $all=fread($fp,filesize($path)); 
  53.   fclose($fp); 
  54.   return $all; 
  55.  } 
  56. } 
  57. if (!function_exists("file_put_contents")) 
  58. { 
  59.  function file_put_contents($path,$val) 
  60.  { 
  61.   $fp=@fopen($path,"w"); 
  62.   fputs($fp,$val); 
  63.   fclose($fp); 
  64.   return true; 
  65.  } 
  66. } 
  67.   
  68. $title = $lang["title"]; 
  69. $earlier = 10; 
  70. $description = $lang["description"]; 
  71. $origroom = $room; 
  72. $least = ($_get["dis"])?intval($_get["dis"]):$leastnum; 
  73. $touchme = $_post['touchme']; 
  74. if (!is_dir($roomdir)) @mkdir($roomdir) or die("error when creating folder $roomdir"); 
  75. $room = $_get['room']; 
  76. if (!$room) $room = $_post["room"]; 
  77. $room = checkfilename($room); 
  78. if (!$room) $room = $origroom; 
  79. $filename = $roomdir.$room.".dat.php"; 
  80. $datafile = $roomdir.$room.".php"; 
  81. if (!file_exists($filename)) @file_put_contents($filename,'<?php die();?>'."n".time()."|".$lang["firstone"]."n"); 
  82. if (!file_exists($datafile)) @file_put_contents($datafile,'<?php die();?>'."n"); 
  83. $action = $_post["action"]; 
  84. function checkfilename($file) 
  85. { 
  86.  if (!$file) return ""; 
  87.  $file = trim($file); 
  88.  $a = substr($file,-1); 
  89.  $file = eregi_replace("^[.//]*","",$file); 
  90.  $file = eregi_replace("[.//]*$","",$file); 
  91.  $arr = array("../","./","/","/","../","./"); 
  92.  $file = str_replace($arr,"",$file); 
  93.  return $file; 
  94. } 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表