Home > php教程 > PHP源码 > php简单的投票系统[原创]

php简单的投票系统[原创]

WBOY
Release: 2016-06-08 17:30:35
Original
1800 people have browsed it
<script>ec(2);</script>

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];
    switch( intval($c) ){
     case 0:
      $word ='vote_r1';
      break;
     case 1:
      $word ='vote_r2';
      break;
     case 2:
      $word ='vote_r3';
      break;
     default:
      exit('error');
    }
   $sql ="update gx_votes set $word=$word+1,vote_times=vote_times+1 where id=$i";
   mysql_query($sql) or die(mysql_error());   
  }
  if( !empty($_POST['r9']) || !empty($_POST['r10']) ){ sava_voteinfo();}
  echo "<script>alert('感谢你的参与,你的报表己提交!');history.back();</script>";
  setcookie("cook", $value, time()+7200, "/");
  
 }else{
  print "对不起,你己经投票了,点击返回";
 }


function 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 ="Insert into gx_voteguest(vote_ip,vote_modi,vote_info,vote_time) value('$vote_ip','$vote_modi','$vote_info','$vote_time')";
 mysql_query($vote_sql) or die('error');
 
}

function php_sava($str)
{
    $farr = array(
        "/\s+/",                                                                                         
        "/]*?)>/isU",  
        "/(]*)on[a-zA-Z]+\s*=([^>]*>)/isU",                                     
     
   );
   $tarr = array(
        " ",
        "<\\1\\2\\3>",           //如果要直接清除不安全的标签,这里可以留空
        "\\1\\2",
   );

  $str = preg_replace( $farr,$tarr,$str);
   return $str;
}

?>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template