php简单的投票系统[原创]
include_once("../inc/connect.php");
$value=$_SERVER['HTTP_HOST'];
if(empty($_COOKIE["cook"])){
if(sizeof($_POST)alert('对不起,你还有选项未选!');history.back();");}
for($i=1;$i
$c =$_POST['r'.$i];
开关( intval($c) ){
案例 0:
$word ='vote_r1';
休息;
情况1:
$word ='vote_r2';
休息;
情况2:
$word ='vote_r3';
休息;
默认值:
退出('错误');
}
$sql ="更新 gx_votes 设置 $word=$word 1,vote_times=vote_times 1 其中 id=$i";
mysql_query($sql) 或 die(mysql_error());
}
if( !empty($_POST['r9']) || !empty($_POST['r10']) ){ sava_voteinfo();}
echo "<script>alert('感谢您的参与,您的报表己提交!');history.back();</script>";
setcookie("cook", $value, time() 7200, "/");
}其他{
print "对不起,你已经投票了,点击返回";
函数 sava_voteinfo(){
$vote_modi =addslashes(php_sava(isset($_POST['r9'])?$_POST['r9']:''));
$vote_info =addslashes(php_sava(isset($_POST['r10'])?$_POST['r10']:''));
$vote_ip =isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'未获取到IP';
$vote_time =date("Y-m-d H:i:s");
$vote_sql ="插入 gx_voteguest(vote_ip,vote_modi,vote_info,vote_time) value('$vote_ip','$vote_modi','$vote_info','$vote_time')";
mysql_query($vote_sql) 或 die('error');
函数 php_sava($str)
{
$farr = 数组(
"/s /",
"/]*?)>/isU",
"/(]*)on[a-zA-Z] s*=([^>]*>)/isU",
);
$tarr = 数组(
“”,
"<\1\2\3>", //如果要直接清除不安全的标签,这里可以留空
“\1\2”,
$str = preg_replace( $farr,$tarr,$str);
返回$str;
?><script>ec(2);</script>