This is a simple voting program, which is a good introductory program for friends who are just learning PHP. Here I will introduce it to you, I hope it will be helpful to my friends.
The system is composed of the following four files: survey.htm with HTML survey form, survey.php that implements the survey function, data.txt that records survey items, and survey.txt that records survey results. Among them, data.txt and survey.txt can be created respectively using NOTEPAD and transferred to the program directory. The file data.txt stores the items to be investigated. Note that each item should occupy one line; survey.txt can be an empty file with no content.
The code of Survey.htm can be as follows:
survey< ;/head>
Note that the survey items in the file data.txt and the survey items above must be consistent in number and order, otherwise errors or surveys will occur The results are inaccurate. At the same time, in order to display the survey results in the form of a bar chart, several bar pictures of different colors should be prepared. Such as: 0.gif, 1.gif, 2.gif, 3.gif, 4.gif, etc.
The following is the survey.php code to implement the survey function:
$data="data.txt";
$votes="survey.txt";
$dataf=file($data); /*Read the items 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); /* Split the data according to the specified string, and then transfer the string back to the array variable*/
if ($result!=1) / *If you have already accepted the investigation*/
{
$file_votes=file($votes, "r");
if ($REMOTE_ADDR == $file_votes[1]) /*Check if it is the same person */
{
echo "
You have already voted, thank you for your participation!";
exit ;
}
/*If the IP is not repeated, execute the following procedure*/
http://www.bkjia.com/PHPjc/445093.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445093.htmlTechArticleThis is a simple voting program, which is a good introductory program for friends who are just learning PHP. Here I will introduce it to you, I hope it will be helpful to my friends. The system is...