Simple voting system [anti-Brush program Refresh]_php Tutorial

Source: Internet
Author: User
simple voting system [anti-brush program Refresh]

Include_once (".. /inc/connect.php ");
$value =$_server[' Http_host '];
if (Empty ($_cookie["Cook"])) {
if (sizeof ($_post) <9) {exit ("");}
for ($i =1; $i <=8; $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 "";
Setcookie ("Cook", $value, Time () +7200, "/");

}else{
Print "Sorry, you have already voted, click Back";
}


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 ']: ' Not acquired to IP ';
$vote _time =date ("y-m-d h:i:s");
$vote _sql = "Insert into SS (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+/",
"/< (\/?) (script|i?frame|style|html|body|title|link|meta|\?| \%) ([^>]*?) >/isu ",
"/(<[^>]*) on[a-za-z]+\s*= ([^>]*>)/isu",

);
$tarr = Array (
" ",
"<\\1\\2\\3>",//If you want to clear unsafe labels directly, you can leave this blank
"\\1\\2",
);

$str = Preg_replace ($farr, $tarr, $STR);
return $str;
}

?>

Recently, this cookie-like program can erase cookies, one way I have done before, first client anti-brush and then save the user's IP to the database, In this way, the user will use the PHP program to check whether it is within our specified time to operate, so you can achieve a real anti-brush.

http://www.bkjia.com/PHPjc/629751.html www.bkjia.com true http://www.bkjia.com/PHPjc/629751.html techarticle simple voting system [anti-brush program refresh]? php include_once (.. /inc/connect.php); $value =$_server[' Http_host ']; if (empty ($_cookie[cook))) {if (sizeof ($_post) 9) {exit (Scriptalert (' Sorry ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.