求助:这vote.asp为何运行不了,请帮忙测试!(有关投票的)
求助:这vote.asp为何运行不了,请帮忙测试!代码在附件
Vote.rar
(5.18 KB)
,是什么问题,请高手帮我诊断修改,先谢谢!!!这是在网上下载的一|简单的投票代码,但我却运行不了。出现:/*
Author : Rimifon @ 8:39 2013-6-4
MyHome : http://www.
*/
var sys = {[0]Script error detected at line 1,col[0].
Source line: /*
Description: 缺少语句
文件代码如下:
<%@ language="livescript" codepage="65001" %><%
/*
Author : Rimifon @ 8:39 2013-6-4
MyHome : http://www.
*/
var sys = {
AdminMode : true, // 数据维护完之后设置为false
Title : "单文件ASP评选投票系统",
ConnStr : "Provider=Microsoft.Jet.OleDB.4.0; dBase 5.0; Database=" + Server.MapPath("."),
Time : new Date
}, rs = new ActiveXObject("Ador.RecordSet");
/* ========== 华丽丽滴分割线 ========== */
rs.activeConnection = sys.ConnStr;
try { Boot(); }
catch(err){ ShowErr(err); }
rs.activeConnection.Close();
/* ========== 华丽丽滴分割线 ========== */
/* 引导程序 */
function Boot()
{
// 初始化参数
rs.LockType = 3;
// 呈现不同页面
switch(Request.QueryString("Mode").Item)
{
case "Ajax": return Ajax();
case "Sort": return ShowPage(SortHead, SortBody);
case "Last": return ShowPage(SortHead, LastBody);
}
ShowPage(HomeHead, HomeBody);
}
/* ======== 主 控 页 ======== */
function ShowPage(FuncH, FuncB)
{
if(sys.AdminMode) { FuncH = null; FuncB = AdminBody; }
%><!doctype html><html xmlns:z="http://www.
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%= sys.Title %></title>
<!-- 通用CSS部分 -->
<style type="text/css">
body{ font: 4mm/7mm simsun; margin: 0mm }
a{ text-decoration: none; color: #123456 }
.row{ width: 1000px; margin: 0mm auto; display: block }
z\:Banner{ height: 1in; background-color: #def; text-indent: 1cm; font: bold 5mm/2cm FZYaoTi,Microsoft Yahei; color: #456789 }
z\:Menu{ text-indent: 4mm; background-color: #abcdef }
z\:Foot{ text-align: center; color: #abc }
</style><%
if(FuncH){ FuncH(); }
%></head><body>
<z:Banner class="row"><%= sys.Title %></z:Banner>
<z:Menu class="row">
<a href="?">投票首页</a> |
<a href="?Mode=Sort">投票排行</a> |
<a href="?Mode=Last">行为分析</a>
</z:Menu>
<% FuncB(); %>
<z:Foot class="row"><hr size="1" /><%= sys.Title %> 版权申明
<a href="Vote.rar">源码下载</a>
[<%= new Date - sys.Time %>ms]</z:Foot>
</body></html><%
}
/* ======== 投票首页 ======== */
function HomeHead()
{
// 记录访问者打开投票页面的时刻
Session("IncomeTime") = sys.Time - 0;
%><style type="text/css">
z\:Description{ background-color: #f0f7ff }
z\:Description div{ padding: 3mm 1in }
z\:VoteList{ background-color: #f0f7ff }
z\:VoteList h3{ margin: 0mm; padding: 0mm 5mm; background-color: #abcdef; color: #123456; font: bold 4mm/7mm simsun }
div.list{ padding: 5mm 0mm 5mm 1cm }
z\:Vote{ float: left; width: 150px; padding: 12px 12px 0mm 12px; height: 2in; margin: 4px; border: 1px solid #def; font: 9pt/18px simsun; text-align: center; background-color: #fff }
z\:Vote img{ width: 120px; height: 160px; background-color: #def }
z\:Vote input{ font: 9pt/9pt simsun; height: 18px }
</style><script type="text/javascript">
var http = self.XMLHttpRequest ? new XMLHttpRequest
: new ActiveXObject("Microsoft.XMLHttp");
function Post(data, func)
{
http.open("POST", "?Mode=Ajax", true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.onreadystatechange = function()
{
if(http.readyState < 4) return;
func(http.responseText);
}
http.send(data);
}
function Vote(nmbID)
{
Post("Cmd=Vote&ID=" + nmbID, function(text)
{
alert(text);
});
}
</script><% }
function HomeBody()
{ %><z:Description class="row"><div>
<b>关于本次投票的相关文字说明:</b>
<ol>
<li>投票时免验证码输入,是绝大多数投票用户的强烈要求。</li>
<li>通过代理上网的网友只是极个别现象,因此本投票系统将忽略掉通过代理(X-Forwarded-For)上网的用户。</li>
<li>实际投票过程中查找和确认投票项需要时间,用户只能在打开投票首页并在两秒钟之后才能成功投票。</li>
<li>IP记录库仅保留20分钟内投票的用户,可有效防止数据库过大造成的IP核查缓慢,即使在受到刷票攻击的情况下,服务器也不容易宕机。</li>
<li>实现投票的行为分析功能,可根据投票频率、用户UA、IP等信息分析是否有刷票行为。</li>
</ol>
</div></z:Description>
<z:VoteList class="row">
<h3>投票列表</h3>
<div class="list"><%
rs.Open("Vote");
while(!rs.EOF)
{ %>
<z:Vote>
<img<%= rs("Icon").value ? " src=\"" + rs("Icon") + "\"" : "" %> /><br />
<%= rs("ID") %>. <a<%= rs("Url").value ? " href=\"" + rs("Url") + "\" target=\"_blank\"" : "" %>><%= rs("Name") %></a> <input type="button" value="投票" onclick="Vote(<%= rs("ID") %>)" />
</z:Vote><%
rs.MoveNext();
}
rs.Close();
%>
<p style="clear: both; margin: 0mm"></p>
</div>
</z:VoteList><% }
/* ======== 投票排行 ======== */
function SortHead()
{ %><style type="text/css">
table{ width: 8in; margin: 1cm auto; text-align: center; color: #123456; font: 13px/6mm simsun }
table, td, th{ border: solid 1px #abc; border-collapse: collapse }
th{ background-color: #def }
td.id{ background-color: #f0f7ff }
</style><% }
function SortBody()
{ %>
<table>
<caption><h3>投票排行</h3></caption>
<tr>
<th>编号</th><th>名称</th><th>票数</th>
<th>编号</th><th>名称</th><th>票数</th>
<th>编号</th><th>名称</th><th>票数</th>
</tr><%
var nmbVote = 0;
rs.Open("select ID, Name, Poll from Vote order by Poll desc, ID");
while(!rs.EOF)
{ %>
<tr><%
for(var i = 0; i < 3; i++)
{
if(!rs.EOF) { %>
<td class="id"><%= rs("ID") %></td><td><%= rs("Name") %></td><td><%= rs("Poll") %></td><%
nmbVote += rs("Poll").value;
rs.MoveNext();
} else { Response.Write("<td>-</td><td>-</td><td>-</td>"); }
} %>
</tr><%
}
rs.Close(); %>
<tr><td colspan="9">目前总票数:<%= nmbVote %> 票</td></tr>
</table>
<% }
/* ======== 行为分析 ======== */
function LastBody()
{ %><table>
<caption><h3 align="center">行为分析</h3></caption>
<tr>
<th>编号</th><th>时间</th><th>名称</th><th>IP</th><th width="456">信息</th>
</tr><%
rs.Open("select top 100 a.ID, b.Name, IP, UA, Proxy, [Time] from IPList a left join Vote b on b.ID=a.ID order by [Time] desc");
while(!rs.EOF)
{
var date = new Date(rs(5).value);
%>
<tr>
<td class="id"><%= rs(0) %></td>
<td title="<%= date.getVarDate() %>"><%= date.toLocaleTimeString() %></td>
<td><%= rs(1) %></td>
<td><%= rs(2) %></td>
<td><%= rs(3) %></td>
</tr><%
rs.MoveNext();
}
rs.Close(); %>
</table><% }
/* ======== 错误页面 ======== */
function ShowErr(err)
{
Response.Clear();
if(Request.QueryString("Mode").Item == "Ajax")
return Response.Write(err.message);
sys.AdminMode = false;
ShowPage(null, function(){ %><div class="row"><div style="background-color: #f0f7ff; padding: 1in 2in; text-align: center; font: 5mm/1cm verdana; color: #789">出错啦!<br /><%= err.message %></div></div><% });
}
/* ======== Ajax处理 ======== */
function Ajax()
{
switch(Request.Form("Cmd").Item)
{
case "Vote" : return Vote();
case "EditItem": return EditItem(); // 保存项目
case "DelItem": return DelItem(); // 删除项目
}
Response.Write("Wait for command.");
}
/* ======== 管理界面 ======== */
function AdminBody()
{ %><p></p><style type="text/css">
table, th, td{ border: 1px solid #abc; font: 9pt/9pt simsun; border-collapse: collapse; padding: 0mm }
th{ background-color: #def; font: bold 9pt/9pt simsun; padding:1mm; color: #123456 }
td{ text-align: center;padding: 2px }
input{ font: 9pt/9pt simsun; border: none }
</style><script type="text/javascript">
var http = self.XMLHttpRequest ? new XMLHttpRequest
: new ActiveXObject("Microsoft.XmlHttp");
function Save(sender)
{
var tr = sender.parentNode;
var nmbID = tr.cells[0].innerHTML | 0;
self.curIpt = tr.getElementsByTagName("input");
Post("Cmd=EditItem&ID=" + nmbID + "&Name=" + getVal(0) + "&Logo="
+ getVal(1) + "&Url=" + getVal(2) + "&Description=" + getVal(3),
function(text)
{
if(nmbID) return alert(text);
//tr.parentNode.appendChild(tr.cloneNode(true));
location.reload();
});
}
function Del(sender)
{
if(!confirm("确定要删除这条记录吗?")) return;
var tr = sender.parentNode;
Post("Cmd=DelItem&ID=" + tr.cells[0].innerHTML, function(text)
{
alert(text);
tr.parentNode.deleteRow(tr.rowIndex);
});
}
function getVal(id)
{
return encodeURIComponent(curIpt[id].value);
}
function Post(str, func)
{
http.open("POST", "?Mode=Ajax", true);
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http.onreadystatechange = function()
{
if(http.readyState < 4) return;
func(http.responseText);
}
http.send(str);
}
</script><h4 align="center">提示:数据维护完成之后请将源码中AdminMode设置为false</h4>
<table align="center">
<tr><th>ID</th><th>名称</th><th>图标网址</th><th>介绍网址</th><th>简要备注</th><th>操作</th></tr>
<tr>
<td>New</td>
<td><input size="12"></td>
<td><input /></td>
<td><input /></td>
<td><input /></td>
<td><input type="button" value="添加项目" onclick="Save(parentNode)" /></td>
</tr><%
try{ rs.Open("Vote"); }
catch(err)
{
rs.Open("create table Vote(ID int, Name varchar(64), Icon varchar(254), Url varchar(254), Message varchar(254), Poll int)");
rs.Open("create table IPList(ID int, IP varchar(41), UA varchar(254), Proxy varchar(254), [Time] int)");
rs.Open("Vote");
%>
<caption><h4>数据库初始化成功</h4></caption><%
}
if(rs.fields.count < 2) throw new Error("请尝试设置目录权限并重新初始化数据库。");
while(!rs.EOF)
{ %>
<tr>
<td><%= rs(0) %></td>
<td><input size="12" value="<%= rs(1) %>" /></td>
<td><input value="<%= rs(2) %>" /></td>
<td><input value="<%= rs(3) %>" /></td>
<td><input value="<%= rs(4) %>" /></td>
<td>
<input type="button" value="修改" onclick="Save(parentNode)" />
<input type="button" value="删除" onclick="Del(parentNode)" />
</td>
</tr><%
rs.MoveNext();
}
rs.Close();
%>
</table><p></p><% }
/* Ajax部分处理程序 */
function EditItem()
{
if(!sys.AdminMode) return Response.Write("403 Forbidden.");
var nmbID = Request.Form("ID").Item | 0;
if(!nmbID)
{
rs.Open("select max(ID) from Vote");
nmbID = (rs(0).value | 0) + 1;
rs.Close();
rs.Open("select * from Vote where ID<0");
}
else rs.Open("select * from Vote where ID=" + nmbID);
if(rs.EOF)
{
rs.AddNew();
rs("ID").value = nmbID;
rs("Poll").value = 0;
}
rs("Name").Value = Request.Form("Name").Item;
rs("Icon").Value = Request.Form("Logo").Item;
rs("Url").Value = Request.Form("Url").Item;
rs("Message").Value = Request.Form("Description").Item;
rs.Update();
rs.Close();
Response.Write("保存成功");
}
function DelItem()
{
if(!sys.AdminMode) return Response.Write("403 Forbidden.");
rs.Open("delete from Vote where ID=" + (Request.Form("ID").Item | 0));
Response.Write("删除成功");
}
function Vote()
{
var nmbID = Request.Form("ID").Item | 0;
// 正常情况下只有极个别用户会使用代理,可忽略该票。
if(Request.ServerVariables("HTTP_X_FORWARDED_FOR").Item)
return Response.Write("对不起,不允许通过代理投票");
// 判断打开投票页面的时间
var sesTime = Session("IncomeTime");
// 从打开投票页面到点击投票的间隔不能小于2秒
if(!sesTime || sys.Time - sesTime < 2000)
return Response.Write("别急,稍候再试试吧。");
// 判断该IP是否已投票(20分钟之内)
var strIP = Request.ServerVariables("Remote_Addr").item;
rs.Open("select count(0) from IPList where ID=" + nmbID + " and IP='" + strIP + "' and [Time]>" + (sys.Time - 20 * 60 * 1000));
var isVote = rs(0).value;
rs.Close();
if(isVote) return Response.Write("20分钟内同一票只允许投一次。");
// 允许投票
rs.Open("update Vote set Poll=Poll+1 where ID=" + nmbID);
// 记录该投票IP,重复利用20分钟之前的数据,以防暴库。
rs.Open("select * from IPList where [Time]<" + (sys.Time - 20 * 60 * 1000) + " order by [Time] asc");
if(rs.EOF) rs.AddNew();
rs("ID").value = nmbID;
rs("IP").value = strIP;
rs("UA").value = (Request.ServerVariables("HTTP_USER_AGENT").Item || "").slice(0, 254);
rs("Time").value = sys.Time - 0;
// 允许代理投票的情况下备用
rs("Proxy").value = (Request.ServerVariables("HTTP_X_FORWARDED_FOR").Item || "").slice(0, 254);
rs.Update();
rs.Close();
// 投完后清空时间戳
Session.Contents.Remove("IncomeTime");
Response.Write("感谢您的投票");
}
%>
[此贴子已经被作者于2017-5-18 22:28编辑过]