Php simple online voting system source code download,-PHP source code

Source: Internet
Author: User
Ec (2); php simple online voting system source code download, the last time you want to work with a public they said they want me to write a simple voting system, but each IP can only vote once, well, the following is the simplest voting system I have written. It is implemented using php. create a database first. there are two items to record the number of votes and related information. One is to record IP addresses. CREATETABLEIFNOTEXISTS 'lj _ vote' (& nbsp; 'id' int (8) NOTNULL script ec (2); script

Php simple online voting system source code download. The last time I tried to work with your company, they told me to write a simple voting system, but each IP Address can only be cast once, well, the following is the simplest voting system I have written. It is implemented using php.

Create a database first. There are two items to record the number of votes and related information. One is to record the IP address.

Create table if not exists 'lj _ vote '(
'Id' int (8) not null auto_increment,
'V _ type' int (4) default '1 ',
'V _ caption 'varchar (500) default null comment'. The image address or description can be used here ',
'V _ hits 'int (8) not null default '0' comment' votes ',
'V _ ip' text comment' the voting ip address is unique and there is always only one chance ',
'V _ name' varchar (50) default NULL comment' file author ',
'V _ id' int (4) default null comment 'unique number ',
Primary key ('id ')
) ENGINE = InnoDB default charset = gb2312 AUTO_INCREMENT = 21;

Database that records IP addresses.

Create table if not exists 'lj _ ip '(
'Id' int (8) not null auto_increment,
'V _ ip' varchar (50) default NULL,
'V _ time' datetime default NULL,
Primary key ('id ')
) ENGINE = InnoDB default charset = gb2312 AUTO_INCREMENT = 4;

Well, the data is ready. Let's see how php achieves voting.

$ Value = $ _ SERVER ['HTTP _ host'];
$ Vote1 = isset ($ _ POST ['a'])? $ _ POST ['a']: '';
$ Vote2 = isset ($ _ POST ['B'])? $ _ POST ['B']: '';
$ Ip = get_real_ip ();
If (empty ($ vote1) | empty ($ vote2 )){
Exit ("script" alert ('you have not selected Project'); 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. Click Back ");
} Else {
Mysql_query ("update lj_vote set v_hits = v_hits + 1 where v_name = '$ vote1'") or die ('A ');
Mysql_query ("update lj_vote set v_hits = v_hits + 1 where v_name = '$ vote2'") 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, you have successfully voted '); 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 ']);
}

Okay. The voting system will not be complete. I will not write down the voting htm page myself.
?>

Declaration: This site is originally reproduced, please note: 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.