PHP Simple Online Voting system source code download,

Source: Internet
Author: User

PHP Simple Online Voting system source download, the last time you and a public cooperation they said to me to write a simple voting system, but each IP can only vote once, well, the following is I wrote a most simple voting system, is implemented in PHP.

First, create the database. There are two records of voting times with related information one is record IP.

CREATE TABLE IF not EXISTS ' Lj_vote ' (
' ID ' int (8) not NULL auto_increment,
' V_type ' int (4) Default ' 1 ',
' v_caption ' varchar default NULL COMMENT ' Here you can place a picture address or an article description ',
' V_hits ' int (8) Not NULL default ' 0 ' COMMENT ' Poll number ',
' v_ip ' text COMMENT ' vote IP is unique, always only one chance ',
' v_name ' varchar default NULL COMMENT ' author of the Works ',
' v_id ' int (4) Default NULL COMMENT ' unique number ',
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT charset=gb2312 auto_increment=21;

Record the IP database.

CREATE TABLE IF not EXISTS ' lj_ip ' (
' ID ' int (8) not NULL auto_increment,
' v_ip ' varchar default NULL,
' V_time ' datetime default NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT charset=gb2312 auto_increment=4;

Well, all right, all the data is ready. Let's see how PHP is going to make the vote.

<?php
$value =$_server[' Http_host '];
$vote 1 =isset ($_post[' a '])? $_post[' A ']: ';
$vote 2 =isset ($_post[' B '])? $_post[' B ']: ';
$ip =get_real_ip ();
if (Empty ($vote 1) | | empty ($vote 2)) {
Exit ("<script>alert (' You have not selected item '); History.back ();</script>");
}else{
$re =mysql_query ("Select V_ip from lj_ip where v_ip= ' $ip") or Die (' error ');
if (mysql_num_rows ($re)) {
Exit ("Sorry, you have already voted, <a href=# onclick=\" history.back (); \ "> Click Back </a>");
}else{
mysql_query ("Update lj_vote set v_hits=v_hits+1 where v_name= ' $vote 1 '") or Die (' a ');
mysql_query ("Update lj_vote set v_hits=v_hits+1 where V_name= ' $vote 2 '") or Die (' B ');
mysql_query ("INSERT into LJ_IP (v_ip,v_time) value (' $ip ', '". Date ("Y-m-d h:i:s"). "") or Die (' IP ');
Exit ("<script>alert" (' Congratulations, successful vote '); History.back ();</script> ");
}
}

function Show_hits ($value) {
$result =mysql_query ("select * from Lj_vote where v_name= ' $value") or Die (' error ');
Return @mysql_num_rows ($result);
}

function Get_real_ip () {
$ip =false;
if (!empty ($_server["HTTP_CLIENT_IP"])) {
$ip = $_server["Http_client_ip"];
}
if (!empty ($_server[' http_x_forwarded_for ')) {
$ips = Explode (",", $_server[' http_x_forwarded_for '));
if ($IP) {array_unshift ($ips, $ip); $ip = FALSE;}
for ($i = 0; $i < count ($ips); $i + +) {
if (!eregi ("^ (10|172\.16|192\.168) \.", $ips [$i])) {
$ip = $ips [$i];
Break
}
}
}
Return ($ip $ip: $_server[' remote_addr ']);
}

OK, OK, the voting system is not finished, vote HTM page I have not written it myself.
?>

Disclaimer: Original site reproduced please specify: www.111cn.net

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.