我如何设定一个人可以再次投票的时间?
我有一个投票系统,您不必登录,我想知道如何将其设置为每天可以投票一次,可以通过阻止 IP 或类似的方式。我不喜欢有一个数据库,
<script type="text/javascript">
var clicks = 0;
function linkClick(){
document.getElementById('clicked').value = ++clicks;
}
document.write('<a href="#" onclick="linkClick()">Vote Now!</a>');
$('#clicked').parent().bind('click', function(evt) {
$(this).unbind('click');
/* do long time task....
evt.preventDefault();
});
</script>
You have clicked the link <input id="clicked" size="3" onfocus="this.blur();" value="0" > times
这个代码就目前而言,只会让使用投票一次且仅一次,我希望每 24 小时一次,并且以 html 形式,提前谢谢
i have a voting system that you dont have to login to and i want to know how i can set it to where they can vote once per day, either by blocking IP or something of the sort. i prefer not to have a database
<script type="text/javascript">
var clicks = 0;
function linkClick(){
document.getElementById('clicked').value = ++clicks;
}
document.write('<a href="#" onclick="linkClick()">Vote Now!</a>');
$('#clicked').parent().bind('click', function(evt) {
$(this).unbind('click');
/* do long time task....
evt.preventDefault();
});
</script>
You have clicked the link <input id="clicked" size="3" onfocus="this.blur();" value="0" > times
this code as it stands will only let a use vote once and only once, i would like it to be every 24 hours and in html, thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 javascript 或 HTML 中不可能以安全的方式实现这一点。原因是,作为网络用户,我可以清除 cookie、打开新浏览器或以编程方式调用您的服务器,而无需使用您的用户界面。这意味着您需要在服务器上安装一些东西来防止我在一天内实际提交两次,无论网页是什么样子。
我的建议是使用用户登录来验证用户没有发布两次。
It's not possible to implement this in a safe way in javascript or HTML. The reason is that as a web-user I can clear my cookies, open a new browser, or make calls to your server programatically without having to use your user interface. This means you need something on the server to prevent me from actually submitting twice within a day, regardless of what the web-page looks like.
My recommendation would be to use a user-login to verify that the user hasn't posted twice.
您可以创建一个 cookie 并每天检查以查看他们是否已经投票。尽管 JCO611 是正确的,但这很容易被绕过。我建议使用一些服务器端代码。
有关 javascript 中 cookie 的更多信息:
http://www.quirksmode.org/js/cookies.html
You could create a cookie and check that each day to see if they have voted already. Although JCO611 is correct, this is easily bypassed. I would recommend using some server side code.
For more on cookies in javascript:
http://www.quirksmode.org/js/cookies.html