登录模块加载中...
会员投稿 投稿指南 今天是:
打印本页 | 关闭窗口 | 双击滚屏 您的位置首页>>网页制作学习园地>>CGI教程>>CGI脚本编码>>CGI聊天室
CGI聊天室
来源:网页制作学习园地 ‖ 作者:网页制作学习园地 ‖ 点击: ‖ 时间:07-12-19 14:55:08 ‖ 【 】‖ 我要投稿

    源代码如下:


#!/usr/bin/perl
#############################################################
# Thank you for downloading EveryChat... This script was built
# and tested under Perl 5.003 for Win32, but should work on
# any platform. PLEASE DO NOT REDISTRIBUTE THIS SCRIPT! See
# README.TXT for more information. This script may be
# obtained FREE OF CHARGE from the EveryChat home page at:
#
# http://www.cs.hope.edu/~hahnfld/everychat/
#
# THIS IS VERSION 3.5 - Now For EVERY Browser!


#############################################################
# CONFIGURATION (MODIFY THIS SECTION)
# place the absolute path to your chat room message files
# here (include a trailing slash).


$filepath='/home/httpd/elvis/chatroom/messages/';


# place the file extention of your chat room message files
# here, including the dot. It is probably .htm or .html


$filext='.html';


# setting this flag will make messages scroll from top to
# bottom, making the script compatible with EVERY browser.
# See the readme.txt file under OPTIONS for more details!


$iecompatible=0;


#############################################################
# Section 1: read in the form data and initialize page


print "Content-type: text/html\nPragma: no-cache\n\n";
&get_form_data;


#############################################################
# Section 2: check if [room].html exists and if so, read in
# the old message file


$formdata{'room'} =~ s/\W//g;
unless (open(HTMLOLD, "$filepath$formdata{'room'}$filext"))
{
die 'The following room does not exist on this server: ';
}
@lines=;
close(HTMLOLD);


#############################################################
# Section 3: get the time and format to look nice


$now_string = localtime;
@thetime = split(/ +/,$now_string);
@theclock = split(/:/,$thetime[3]);
$ampm = 'am';
if ($theclock[0] > 11)
{ $ampm = 'pm'; }
if ($theclock[0] == 0)
{ $theclock[0] = 12; }
if ($theclock[0] > 12)
{ $theclock[0] -= 12; }
else
{ $theclock[0] += 0; }


#############################################################
# Section 4: initialize the message form after logon and
# write new messages file


print "\n";
if ($formdata{'logoff'} eq '1')
{
print "

谢谢你使用本聊天室\!


\n";
}
else
{
print "
\n\n\n\n\n
\n";
print "
你想说\:\n\\n";
print "\n";
print "\n";
print "";
print "
\n
\n";
print "
\n";
print "\n";
print "\n";
print "\n";
print "";
print "
\n


\n";
print "Hit \"post\" without entering a message to refresh the screen\.\.\.\n";
}


#############################################################
# Section 5: output the new message page


if ($formdata{'message'} ne "") {
$newmessage = "\\$formdata{'username'}\ 说\,\"$formdata{'message'}\" \($thetime[0] $theclock[0]\:$theclock[1]$ampm\)\n";
open (NEW, ">$filepath$formdata{'room'}$filext");
print NEW '';
print NEW "\n";
if ($iecompatible) {
print NEW $newmessage;
print $newmessage;
for ($i = 1; $i < 15; $i++)
{
print NEW "$lines[$i]";
print "$lines[$i]";
}
print NEW '
boysss 1998.5.6';
}
else {
for ($i = 2; $i < 16; $i++)
{
print NEW "$lines[$i]";
print "$lines[$i]";
}
print NEW $newmessage;
print $newmessage;
print NEW '
boysss 1998.5.6';
}
print NEW "\n";
close(NEW);
}
else {
for ($i = 1; $i < 16; $i++)
{
print "$lines[$i]";
}
}
print "
\n";
exit 0;


#############################################################
# Section 6: subprograms to perform useful tasks


sub get_form_data {
$buffer = "";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair (@pairs)
{
@a = split(/=/,$pair);
$name=$a[0];
$value=$a[1];
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$value =~ s/\+/ /g;
$value =~ s/\$value =~ s/\>/\>\;/g; # html tag removal (remove these lines to enable HTML tags in messages)
$value =~ s/\r//g;
push (@data,$name);
push (@data, $value);
}
%formdata=@data;
%formdata;
}

加入收藏:  加入收藏夹  | 发送给好友:  发送给好友
责任编辑:0
  • 上一篇:CGI留言薄
  • 下一篇:CGI计数器
  • 请文明参与讨论,禁止漫骂攻击。  
    网友评论