Simple voting system [refresh anti-refresh program] _ PHP Tutorial

Source: Internet
Author: User
Simple voting system [refresh anti-refresh program]. Simple voting system [anti-refresh program]? Phpinclude_once (.. incconnect. php); $ value $ _ SERVER [HTTP_HOST]; if (empty ($ _ COOKIE [cook]) {if (sizeof ($ _ POST) 9) {exit (scriptalert (sorry Simple voting system [refresh anti-refresh program]

Include_once ("../inc/connect. php ");
$ Value = $ _ SERVER ['http _ host'];
If (empty ($ _ COOKIE ["cook"]) {
If (sizeof ($ _ POST) <9) {exit ("script" alert ('sorry, you still have the option not selected! '); History. back (); script ");}
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 "script" alert ('thank you for your participation. your report has been submitted! '); History. back (); script ";
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 ']: 'Ip not obtained ';
$ 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>", // leave this field blank if you want to clear insecure labels directly.
"\ 1 \ 2 ",
);

$ Str = preg_replace ($ farr, $ tarr, $ str );
Return $ str;
}

?>

Recently, this kind of cookie-based program can clear and refresh cookies. One way is that I have done it before. First, the client first prevents the refresh and then saves the user's IP address to the database, in this way, the user will use the php program to check whether the operation is performed within the specified time so that the real anti-click protection can be implemented.

Why? 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.