基本功能:能登陆,聊天,记录在线人数IP事件,能控制聊天的字体颜色,自动把转化聊天中网址为链接地址,能定制聊天室标题、广告信息等等。使用文本作为存储媒体,又兴趣可以参考代码,并且进行扩展。
其实PHP作为快速开发的脚本语言是很棒的!
===代码===
以下为引用的内容: /** * 黑夜路人简易聊天室 * 作者: heiyeluren * 创建: 2005-8-10 22:42 * 修改: 2005-8-11 23:25 */ error_reporting(7); session_start(); header("ContentType:text/html;charset=gb2312"); define("SCRIPT", $_SERVER['SCRIPT_NAME']); define("CHAT_NOTE", "./chat.txt"); define("ONLINE_LIST", "./online.txt"); define("REF_TIME", 5); define("CHAT_NAME", "黑夜路人聊天室"); define("AD_MSG", "今天是中国情人节, 祝大家情人节快乐!!"); //获取值 if (isset($_GET['action']) && !empty($_GET['action'])) { $action = $_GET['action']; } //如果已经登陆那么直接跳到聊天界面 if (!isset($_GET['action']) && isset($_SESSION['username'])) { header("location:".SCRIPT."?action=chat"); } //登陆提示 if (!isset($_GET['action'])) { if (!session_is_registered('username')) { echo " [ ".CHAT_NAME." ] © 2005
"; exit; } } //校验登陆 if ($action=='login') { if (isset($_POST['login_user']) && !empty($_POST['login_user'])) { $username = $_POST['login_user']; } else { $username = "游客"; } session_register('username'); save_online($username, get_client_ip()); header("location:".SCRIPT."?action=chat"); } //开始聊天www.knowsky.com if ($action=="chat") { $online_sum = get_online_sum(); echo " name=show_win width=800 height=450 scrolling=auto frameborder=0> [当前在线:$online_sum] height=60 scrolling=no frameborder=0> "; } //说话界面 if ($action=="say") { echo " onSubmit='return check()'> [".$_SESSION['username']."]说:maxlength=500 name=chatmsg style=' background-color:#99CC99; width:550px; height:22px; border:1px solid:#000000'> target=_top onclick='return confirm("你确定要退出聊天室吗?")'>退出 <script>function check(){if(document.chat.chatmsg.value=='')<br>{;alert('请输入聊天信息!');return false;}return true;}</script> "; } //保存说话 if ($action=="save") { if ($_POST['chatmsg']!="") { save_chat($_POST['chatmsg'], $_SESSION['username'], $_POST['usercolor']); } header("location:".SCRIPT."?action=say"); } //显示聊天记录 if ($action=="show") { echo ""; echo "CONTENT='".REF_TIME.";URL=".SCRIPT."?action=show'>"; if (file_exists(CHAT_NOTE)) { $chat_msg = @file_get_contents(CHAT_NOTE); echo $chat_msg; } else { echo "目前没有人说话"; } } //退出聊天室 if ($action=="logoff") { unset($_SESSION['username']); session_destroy(); header("location:".SCRIPT); } /* 基本函数 */ //保存聊天记录函数 function save_chat($msg, $user, $color) { if (!$fp = fopen(CHAT_NOTE, "a+")) { die('创建聊天记录文件失败, 请检查是否有权限.'); } $msg = htmlspecialchars($msg); $msg = preg_replace('/([http|ftp://])*([a-zA-]) +.([a-zA-Z0-9_-])+.([a-zA-Z0-9_-])+(a-zA-Z0-9_)*/', ' http://www.bkjia.com/PHPjc/364008.html www.bkjia.com true http: //www.bkjia.com/PHPjc/364008.html TechArticle Basic functions: can log in, chat, record the number of people online and IP events, can control the font color of the chat, and automatically convert The URL in the chat is the link address, and you can customize the chat room title and advertising letter... |