- board.html
- <HTML>
- <FORM METHOD="POST" ACTION="/cgi-bin/board.pl">
- <P>你的姓名:<INPUT NAME="name" SIZE="20"></P>
- <p>你的电子邮件地址:<INPUT NAME = "email" SIZE="30"></P>
- <p>你的意见:</p><p><TEXTAREA NAME="suggest" COLS=30 ROWS=4></TEXTAREA></p>
- <INPUT TYPE="submit" value="执行">
- <INPUT TYPE="reset" value="取消">
- <br>
- <P><center><a href="index.html">返回首页</a>
- <a href="data.html">观看留言</a></center></p>
- </FORM></HTML>
board.pl
- #!/usr/bin/perl
- $|=1;
- print "Content-type:text/html\n\n";
- read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
- @pairs=split(/&/,$buffer);
- foreach $pair(@pairs){
- ($name,$value)=split(/=/,$pair);
- $value=~s/\+/ /g;
- $value=~s/%40/@/g;
- $value=~s/%0D%0A/<br>/g;
- $value=~s/%0d%0a/<br>/g;
- $value=~s/%0a/<br>/g;
- $value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- $FORM{$name}=$value;
- }
- print "留言板";
- print "
留言板
";
- foreach $check(values%FORM){
- if($check eq ""){
- print "
";
- print"
不能有空白字段!
";
- print"
";
- exit;
- }
- }
- $filename="/usr/local/apache2/htdocs/data.html";
- open(FILE,">>$filename") or die "Can't Open $filename!";
- print FILE "我的名字:$FORM{'name'}
\n";
- print FILE "我来自:$ENV{'REMOTE_HOST'}($ENV{'REMOTE_ADDR'})
\n";
- print FILE "电子邮件地址:$FORM{'email'}
";
- print FILE "留言:
$FORM{'suggest'}"
;
- print FILE "
\n";
- close(FILE);
- print "
";
- print "
谢谢赐教!
"
;
- print "如果在留言板中没有看到你的留言,请按刷新按钮。
";
- print "观看留言板";
把board.html拷贝到html目录,board.pl拷贝到cgi目录(参考apache指南)
然后给board.pl设置可执行,而且要设置一个对html目录可写的uid(否则,修改apache配
置里的user),就可以使用留言板了。
阅读(1242) | 评论(0) | 转发(0) |