* Created: 2005-8-10 22:42 * Modified: 2005-8-11 23:25 */error_reporting (7); session_start (); Header ("Contenttype:text/html;charset =gb2312 ");d efine (" SCRIPT ", $_server[' Script_name ');d efine (" Chat_note ","./chat.txt ");d efine (" Online_list ","./ Online.txt ");d efine (" Ref_time ", 5);d efine (" Chat_name "," Night Passerby chat room ");d efine (" Ad_msg "," Today is Chinese Valentine's Day, wish everyone Happy Valentine's Day!! "); /Get value if (Isset ($_get[' action ')) &&!empty ($_get[' action ')) {$action = $_get[' action '];} If you have already logged in then jump directly to the chat interface if (!isset ($_get[' action ')) && isset ($_session[' username ')) {header ("Location:"). SCRIPT. "? Action=chat ");} Login Prompt if (!isset ($_get[' action ')) {if (!session_is_registered (' username ')) {echo "
[ ". Chat_name. "] ©2005
"; Exit }}//Check Login if ($action = = ' Login ') {if (Isset ($_post[' login_user ') &&!empty ($_post[' Login_user '])) {$username = $ _post[' Login_user ']; } else {$username = "visitor";} session_register (' username '); Save_online ($username, Get_client_ip ()); Header ("Location:".) SCRIPT. "? Action=chat ");} Start chatting www.cncms.comif ($action = = "Chat") {$online _sum = Get_online_sum (); echo "
<title>[ ". Chat_name. "]</title>
". Ad_msg. "
[Current online: $online _sum]
";} The speaking interface if ($action = = "Say") {echo "<pead><title>["). Chat_name. "] </title></pead><center><body bgcolor= #C4BFB9 style= ' font-size:12px; ' > ";} Save Speech if ($action = = "Save") {if ($_post[' chatmsg ']!= ") {save_chat ($_post[' chatmsg '], $_session[' username '), $_post[' UserColor ']); } header ("Location:".) SCRIPT. "? Action=say ");} Show Chat History if ($action = = "Show") {echo "<body style= ' font-size:12px ' >"; echo "<meta Http-equiv=refresh content= '" . Ref_time. "; Url= ". SCRIPT. "? Action=show ' > '; if (file_exists (chat_note)) {$chat _msg = @file_get_contents (chat_note); echo $chat _msg; } else {echo "No one is currently speaking";}} Exit the chat room if ($action = = "Logoff") {unset ($_session[' username ')); Session_destroy (); Header ("Location:". SCRIPT);} /* Basic function *///Save chat record function Save_chat ($msg, $user, $color) {if (! $fp = fopen (Chat_note, "A +")) {die (' Create chat log file failed, please check if there is Permissions. '); } $msg = Htmlspecialchars ($msg); $msg = Preg_replace ('/([http|ftp:\/\/]) * ([a-za-]) +\. ( [a-za-z0-9_-]) +\. ([a-za-z0-9_-]) + (A-za-z0-9_) */', ' \\0 ', $msg); $msg = Preg_replace ('/([a-za-z0-9_\.]) +@ ([a-za-z0-9-]) +\. ([a-za-z0-9-]{2,4}) +/', ' \\0 ', $msg); $msg = Date (' h:i:s '). " [". $user."] said: "$msg." <br>\r\n "; if (!fwrite ($FP, $msg)) {die (' write to chat record failed. ')} fclose ($FP);} Write online person information function save_online ($user, $ip) {if (! $fp = fopen (Online_list, "A +")) {die ("failed to create an online list file, check for permissions.");} $user = Str_replace ("|", "", $user); $line = $user. "|". $ip. "|". Time (). " \ r \ n "; if (!fwrite ($FP, $line)) {die ("failed to write online list");} fclose ($FP);} Get online number function Get_online_sum () {if (file_exists (online_list)) {$online _msg = file (online_list); Return count ($online _msg); } else {return 0;}} Get current Login User Ipfunction get_client_ip () {if ($_server[' remote_addr ') {$cip = $_server[' remote_addr '];} elseif (Getenv ("R Emote_addr ") {$cip = getenv (" REMOTE_ADDR "),} elseif (getenv (" Http_client_ip ")) {$cip = getenv (" Http_client_ip ");} E LSE {$CIP = "Unknown";} return $CIP;}? ></ccid_code></pre></td></tr></table></center> <li ><i class= "Layui-icon" >& #xe63a;
|