PHP example: an online survey and voting system written in PHP

Source: Internet
Author: User
Tags php example string back
This is a simple voting program. it is a very good entry program for PHP and friends. I hope it will be helpful to my friends. The system consists of the following four files: sur with HTML investigation form

This is a simple voting program. it is a very good entry program for PHP and friends. I hope it will be helpful to my friends.

The system consists of the following four files: NOTEPAD we can use NOTEPAD to distinguish and upload it to the program directory. The file data.txt is stored in the project to be investigated, and each project should occupy the same line while survey.txt can be an empty file without any content.

The Survey.htm code can be as follows:



Survey




The survey items in the "data.txt" file must be consistent with the number and order of the above survey items. otherwise, errors may occur or the survey results may be inaccurate. At the same time, in order to display the survey results into a bar chart, we should prepare several bar pictures of different colors. For example, 0.gif,1.gif,2.gif,3.gif,4.gif.

The following is the survey. php code for investigation:

Using data='data.txt ';
Using votespolic'survey.txt ';
$ Dataf = file ($ data);/* read the project in the survey project file */
$ File_votes = fopen ($ votes, 'r ');
$ Line_votes = fgets ($ file_votes, 255);/* read the recorded Survey Results */
Fclose ($ file_votes );
$ Single_vote = explode ('|', $ line_votes);/* cut the data according to the specified string, and then pass the string back to the array variable */
If ($ result! = 1)/* if the investigation has been received */
{
$ File_votes = file ($ votes, 'r ');
If ($ REMOTE_ADDR = $ file_votes [1])/* check whether the same person is the same */
{
Echo'

You have already voted. thank you for your participation! ';

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.