|
一个在线调查程序,为什么我的vote.dat里面写入的内容不正确。
出现
4294967295
4294967295
源程序如下:
界面:
[php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 问卷调查 </TITLE>
</HEAD>
<BODY>
<h1>问卷调查</h1>
请你选择最喜欢的网站:
<FORM METHOD = "OST" ACTION="servey.cgi">
<INPUT TYPE="radio" NAME="isp" VALUE="A" Checked>首都在线 263.net<br>
<INPUT TYPE="radio" NAME="isp" VALUE="B">广州网易 163.net<br>
<INPUT TYPE="radio" NAME="isp" VALUE="C">搜狐 SOHU.net<br>
<INPUT TYPE="radio" NAME="isp" VALUE="D">是聆听 21cn.com<br>
<INPUT TYPE="radio" NAME="isp" VALUE="E">亿唐 etang.com<br>
<INPUT TYPE="submit" VALUE="递交">
<INPUT TYPE="reset" VALUE="取消">
</FORM>
欢迎您在线查询<a href="http://127.0.0.1/perltest/sview.cgi">问卷调查结果</a>
</BODY>
</HTML>
[/php]
2.servey.cgi
[php]
#!/usr/bin/perl
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value)=split(/=/, $pair);
$value=~tr/+//;
$value=~s/%([a-f A-F 0-9][a-f A-F 0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$filename="vote.dat";
%NAME=("A", "首都在线", "B", "网易", "C", "搜狐", "D", "是聆听", "E", "亿唐", "E", "亿唐");
print "Content-type:text/html\n\n";
print "<HTML>";
print "<TITLE>问卷调查</TITLE>";
print "<BODY>";
print "<H1>问卷调查</H1>";
open(FILE,"<$filename")||die print"不能打开文件,请和管理员联系\n";
for ($i=0; $i<2;$i++) {
$file[$i] = <FILE>;
$file[$i] = ~s/\n$//;
}
close(FILE);
@item = split(/:/,$file[0]);
@vote = split(/:/,$file[1]);
for ($i=0; $i<@item+1; $i++) {
if ($FORM{'isp'} eq $item[$i])
{
$vote[$i]++;
}
}
open(FILE, ">$filename") || die "Can't open the file";
$item=join(":", @item);
$vote=join(":", @vote);
print FILE "$item\n";
print FILE "$vote\n";
close(FILE);
print "<h2>您是投票给$NAME{$FORM{'isp'}},谢谢您的支持!</h2>";
print "查询<a href=\"http://127.0.0.1/perltest/sview.cgi\">投票结果</a>";
print "</table>";
print "</body></html>";
exit;
[/php]
3.查看程序sview.cgi
[php]
#!/usr/bin/perl
$filename="vote.dat";
%NAME=("A", "首都在线", "B", "网易", "C", "搜狐", "D", "是聆听", "E", "亿唐", "E", "亿唐");
print "Content-type:text/html\n\n";
print "<HTML>";
print "<TITLE>问卷调查</TITLE>";
print "<BODY>";
print "<h1>问卷调查</h1>";
print "当前结果如下:<br>";
open(FILE, "$filename") || die "文件打开错误";
for ($i=0;$i<2 ;$i++) {
$file[$i] = <FILE>;
$file[$i]=~s/\n$//;
}
close(FILE);
@item=split(/:/,$file[0]);
@vote=split(/:/,$file[1]);
print"<table border=1>";
for ($i=0;$i<@item+1 ;$i++) {
print "<tr><td>网站</td><td>$NAME{$item[$i]}</td><td>票数</td><td>$vote[$i]</td><tr>";
}
print "</table>";
print "</body></html>";
exit;
[/php] |
|