投票系统 投票系统功能说明:限定一个IP地址每24小时只能投票一次(非Cookie) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是代码区<body><form enctype="multipart/form-data" action="" method="post"><table border="0"><tr><td bgcolor="#CCCCCC"><font size="4" color="blue">当前最流行的WEB开发语言:</font></td></tr><tr><td><input type="radio" name="vote" value="php" >php</td></tr><tr><td><input type="radio" name="vote" value="asp" >asp</td></tr><tr><td><input type="radio" name="vote" value="jsp" >jsp</td></tr><tr><td><input type="submit" name="sub" value="请投票" ></td></tr></table></form><?php$votefile="vote.txt";//用于计数的文本文件$votefileif(!file_exists($votefile)){ $handle=fopen($votefile,"w+"); fwrite($handle,"0|0|0");//将文件内容初始化 fclose($handle);}if(isset($_POST['sub']))//判断用户是否投票{ if(isset($_POST['vote'])) { $vote=$_POST['vote']; $handle=fopen($votefile,"r+"); $votestr=fread($handle,filesize($votefile)); fclose($handle); $votearray=explode("|",$votestr); echo"<h3>投票完毕!</h3>"; if($vote=='php') { $votearray[0]++; echo"目前PHP的票数为:<font size=5 color='#FF0000'>".$votearray[0]."</font><br>"; } if($vote=='asp') { $votearray[1]++; echo"目前asp的票数为:<font size=5 color='#FF0000'>".$votearray[1]."</font><br>"; } if($vote=='jsp') { $votearray[2]++; echo"目前jsp的票数为:<font size=5 color='#FF0000'>".$votearray[2]."</font><br>"; } //计算总票数 $sum=$votearray[0]+$votearray[1]+$votearray[2]; echo"总票数为:<font size=5 color='#FF0000'>".$sum."</font><br>"; $votestr2=implode("|",$votearray); $handle=fopen($votefile,'w+'); fwrite($handle,$votestr2);//将新字符串写入文件$votefile fclose($handle); }else{ echo"<script>alert('未选择投票选项!')</script>"; }}//限制选择一个IP 24小时内只能投一次$ip = getenv("REMOTE_ADDR");//获取IP echo $ip."<br>"; ?></body> 哦,大牛都回家洗睡了陪孩子了吧,我觉得大牛一般都有孩子了。我觉得CSDN还是人才济济的。2楼说的很在理呀。你就是不想自己写? 最简单的方法就是把IP与投票时间存到一个表里,时间限定24小时,超过24小时IP自动删除接下来每次投票的时候都跟这张表比对一下,如果存在就不让投票!方法给你了,还是自己写吧! 那样还不行啊,还要防止刷屏。大家看下这个了:include("db_conn.php"); $ip=$REMOTE_ADDR; $timelimit=24*60; $res=mysql_query("select * from voteuser where v_id='$v_id' and u_ip='$ip' and u_time + interval $timelimit minute>now() "); if(mysql_num_rows($res)>0) { echo "<script>"; echo "alert('你已经投过票了.请勿重复投票!');"; echo "location.href=vote.php;"; echo "</script>"; break; } else { mysql_query("insert into voteuser (v_id,u_ip,u_time) values('$v_id','$ip','now()')"); }改一改,有错得提示下,谢谢 朋友们,大家帮帮忙啊,我最近进展到这儿了,这个系统的限制还是不能实现啊<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>vote.php</title></head><body><form enctype="multipart/form-data" action="" method="post"><table border="0"><tr><td bgcolor="#CCCCCC"><font size="4" color="blue">当前最流行的WEB开发语言:</font></td></tr><tr><td><input type="radio" name="vote" value="php" >php</td></tr><tr><td><input type="radio" name="vote" value="asp" >asp</td></tr><tr><td><input type="radio" name="vote" value="jsp" >jsp</td></tr><tr><td><input type="submit" name="sub" value="请投票" ></td></tr></table></form><?php$votedatebase="vote.db";//用于计数的文本文件$votefileif(!file_exists($votedatebase)){ $handle=fopen($votedatebase,"w+"); fwrite($handle,"0|0|0");//将文件内容初始化 fclose($handle);}if(isset($_POST['sub']))//判断用户是否投票{ function get_ip(){ $ip = getenv("REMOTE_ADDR");echo $ip."<br>"; $cip = getenv('HTTP_CLIENT_IP'); $xip = getenv('HTTP_X_FORWARDED_FOR'); $rip = getenv('REMOTE_ADDR'); $srip = $_SERVER['REMOTE_ADDR']; if($cip && strcasecmp($cip, 'unknown')) { $onlineip = $cip; } elseif($xip && strcasecmp($xip, 'unknown')) { $onlineip = $xip; } elseif($rip && strcasecmp($rip, 'unknown')) { $onlineip = $rip; } elseif($srip && strcasecmp($srip, 'unknown')) { $onlineip = $srip; } preg_match("/[\d\.]{7,15}/", $onlineip, $match); $onlineip = $match[0] ? $match[0] : 'unknown'; return $onlineip;} if(isset($_POST['vote'])) { $vote=$_POST['vote']; $handle=fopen($votedatebase,"r+"); $votestr=fread($handle,filesize($votefile)); fclose($handle); $votearray=explode("|",$votestr); echo "<script>alert('您已经投过票了,请24小时后再来投票!')</script>"; echo"<h3>投票完毕!</h3>"; if($vote=='php') $votearray[0]++; echo"目前PHP的票数为:<font size=5 color='#FF0000'>".$votearray[0]."</font><br>"; if($vote=='asp') $votearray[1]++; echo"目前asp的票数为:<font size=5 color='#FF0000'>".$votearray[1]."</font><br>"; if($vote=='jsp') $votearray[2]++; echo"目前jsp的票数为:<font size=5 color='#FF0000'>".$votearray[2]."</font><br>"; //计算总票数 $sum=$votearray[0]+$votearray[1]+$votearray[2]; echo"总票数为:<font size=5 color='#FF0000'>".$sum."</font><br>"; $votestr2=implode("|",$votearray); $handle=fopen($votedatebase,'w+'); fwrite($handle,$votestr2);//将新字符串写入文件 fclose($handle);+ @require "chku.php";@header("Content-type:text/html;charset=utf-8;");$u=strtolower(trim($_POST['vote']));//将获取到的值带入,执行SQL查询$chku=mysql_query("select * from votedatabase where vote='$vote'");$chku=mysql_fetch_array($chku);//如果查询结果为空,返回0,有结果返回1echo ($chku!='')?1:0;//关闭mysql数据库mysql_close($chku); exit; } else { echo"<script>alert('未选择投票选项!')</script>"; }}?></body></html> 前两天写了个很简单,两个表,一个放票数等,一个存投票者的信息。投票的就不说了,限制投票的功能我没用24小时,懒省事用的是通过日期判断。也就是1天只能1票。投票时记录下ip和时间,再次投票时检索ip和时间,然后通过当前时间和数据库中的时间对比实现。但是这样只适用于小投票。要是上万条数据的话这样写累死数据库了 vote Discuz 有个投票系统 php 索引数据转化为对象数组方法 求高手 php怎么判断用户点了哪些链接? 求在字符前插入 请问做统计曲线图用什么画图插件好。 关于字符串替换的问题 动画,电影等页面中有大量的<object>......<embed>......</embed></object> 一个用户在一个地方登录,而在其它的地方不允许在同一时间以此用户登录。用PHP怎么实现?以线等、急用 调用打开对话框? 急!!!! 使用 模拟登陆 抓取学校系统的晨跑数据,失败了,请教大神 php无法删除mssql中记录 php数组问题 PHP数字数组相加?
<form enctype="multipart/form-data" action="" method="post">
<table border="0">
<tr><td bgcolor="#CCCCCC">
<font size="4" color="blue">当前最流行的WEB开发语言:</font>
</td></tr>
<tr><td><input type="radio" name="vote" value="php" >php</td></tr>
<tr><td><input type="radio" name="vote" value="asp" >asp</td></tr>
<tr><td><input type="radio" name="vote" value="jsp" >jsp</td></tr>
<tr><td><input type="submit" name="sub" value="请投票" ></td></tr>
</table>
</form>
<?php$votefile="vote.txt";//用于计数的文本文件$votefile
if(!file_exists($votefile))
{
$handle=fopen($votefile,"w+");
fwrite($handle,"0|0|0");//将文件内容初始化
fclose($handle);
}
if(isset($_POST['sub']))//判断用户是否投票
{
if(isset($_POST['vote']))
{
$vote=$_POST['vote'];
$handle=fopen($votefile,"r+");
$votestr=fread($handle,filesize($votefile));
fclose($handle);
$votearray=explode("|",$votestr);
echo"<h3>投票完毕!</h3>";
if($vote=='php')
{
$votearray[0]++;
echo"目前PHP的票数为:<font size=5 color='#FF0000'>".$votearray[0]."</font><br>";
}
if($vote=='asp')
{
$votearray[1]++;
echo"目前asp的票数为:<font size=5 color='#FF0000'>".$votearray[1]."</font><br>";
}
if($vote=='jsp')
{
$votearray[2]++;
echo"目前jsp的票数为:<font size=5 color='#FF0000'>".$votearray[2]."</font><br>";
}
//计算总票数
$sum=$votearray[0]+$votearray[1]+$votearray[2];
echo"总票数为:<font size=5 color='#FF0000'>".$sum."</font><br>";
$votestr2=implode("|",$votearray);
$handle=fopen($votefile,'w+');
fwrite($handle,$votestr2);//将新字符串写入文件$votefile
fclose($handle);
}
else
{
echo"<script>alert('未选择投票选项!')</script>";
}
}
//限制选择一个IP 24小时内只能投一次$ip = getenv("REMOTE_ADDR");//获取IP
echo $ip."<br>";
?></body>
2楼说的很在理呀。你就是不想自己写?
方法给你了,还是自己写吧!
大家看下这个了:
include("db_conn.php"); $ip=$REMOTE_ADDR;
$timelimit=24*60;
$res=mysql_query("select * from voteuser where v_id='$v_id' and u_ip='$ip' and u_time + interval $timelimit minute>now() ");
if(mysql_num_rows($res)>0)
{
echo "<script>";
echo "alert('你已经投过票了.请勿重复投票!');";
echo "location.href=vote.php;";
echo "</script>";
break;
}
else
{
mysql_query("insert into voteuser (v_id,u_ip,u_time) values('$v_id','$ip','now()')");
}
改一改,有错得提示下,谢谢
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>vote.php</title>
</head><body>
<form enctype="multipart/form-data" action="" method="post">
<table border="0">
<tr><td bgcolor="#CCCCCC">
<font size="4" color="blue">当前最流行的WEB开发语言:</font>
</td></tr>
<tr><td><input type="radio" name="vote" value="php" >php</td></tr>
<tr><td><input type="radio" name="vote" value="asp" >asp</td></tr>
<tr><td><input type="radio" name="vote" value="jsp" >jsp</td></tr>
<tr><td><input type="submit" name="sub" value="请投票" ></td></tr>
</table>
</form>
<?php$votedatebase="vote.db";//用于计数的文本文件$votefile
if(!file_exists($votedatebase))
{
$handle=fopen($votedatebase,"w+");
fwrite($handle,"0|0|0");//将文件内容初始化
fclose($handle);
}
if(isset($_POST['sub']))//判断用户是否投票
{
function get_ip()
{ $ip = getenv("REMOTE_ADDR");
echo $ip."<br>";
$cip = getenv('HTTP_CLIENT_IP');
$xip = getenv('HTTP_X_FORWARDED_FOR');
$rip = getenv('REMOTE_ADDR');
$srip = $_SERVER['REMOTE_ADDR'];
if($cip && strcasecmp($cip, 'unknown')) {
$onlineip = $cip;
} elseif($xip && strcasecmp($xip, 'unknown')) {
$onlineip = $xip;
} elseif($rip && strcasecmp($rip, 'unknown')) {
$onlineip = $rip;
} elseif($srip && strcasecmp($srip, 'unknown')) {
$onlineip = $srip;
}
preg_match("/[\d\.]{7,15}/", $onlineip, $match);
$onlineip = $match[0] ? $match[0] : 'unknown';
return $onlineip;}
if(isset($_POST['vote']))
{
$vote=$_POST['vote'];
$handle=fopen($votedatebase,"r+");
$votestr=fread($handle,filesize($votefile));
fclose($handle);
$votearray=explode("|",$votestr);
echo "<script>alert('您已经投过票了,请24小时后再来投票!')</script>";
echo"<h3>投票完毕!</h3>";
if($vote=='php')
$votearray[0]++;
echo"目前PHP的票数为:<font size=5 color='#FF0000'>".$votearray[0]."</font><br>";
if($vote=='asp')
$votearray[1]++;
echo"目前asp的票数为:<font size=5 color='#FF0000'>".$votearray[1]."</font><br>";
if($vote=='jsp')
$votearray[2]++;
echo"目前jsp的票数为:<font size=5 color='#FF0000'>".$votearray[2]."</font><br>";
//计算总票数
$sum=$votearray[0]+$votearray[1]+$votearray[2];
echo"总票数为:<font size=5 color='#FF0000'>".$sum."</font><br>";
$votestr2=implode("|",$votearray);
$handle=fopen($votedatebase,'w+');
fwrite($handle,$votestr2);//将新字符串写入文件
fclose($handle);+
@require "chku.php";
@header("Content-type:text/html;charset=utf-8;");
$u=strtolower(trim($_POST['vote']));//将获取到的值带入,执行SQL查询
$chku=mysql_query("select * from votedatabase where vote='$vote'");
$chku=mysql_fetch_array($chku);
//如果查询结果为空,返回0,有结果返回1
echo ($chku!='')?1:0;
//关闭mysql数据库
mysql_close($chku);
exit;
}
else
{
echo"<script>alert('未选择投票选项!')</script>";
}
}?></body>
</html>
投票的就不说了,限制投票的功能我没用24小时,懒省事用的是通过日期判断。也就是1天只能1票。投票时记录下ip和时间,再次投票时检索ip和时间,然后通过当前时间和数据库中的时间对比实现。但是这样只适用于小投票。要是上万条数据的话这样写累死数据库了