This is a simple voting procedure, for just learning PHP and friends is a very good entry program. Here to introduce you, hope to be helpful to friends.
The system is composed of the following four files: The survey.htm of the HTML survey form, the survey.php of the investigation function, the data.txt of the investigation project are recorded. and record the results of the survey survey.txt. Data.txt and Survey.txt We can create them with notepad and upload them to the program directory. The file data.txt is the project to be investigated, focusing on one line per item, while Survey.txt can be an empty file with no content.
The code for survey.htm can be as follows:
<title>Survey</title>
Pay attention to the survey items in document Data.txt and the above survey items in the number and sequencing must be consistent, otherwise error or the results of the investigation is inaccurate. In order to display the results of the survey as a bar chart, a number of different color bar images should be prepared. such as: 0.gif,1.gif,2.gif,3.gif,4.gif and so on.
The following is the survey.php code that implements the survey function:
$data = "Data.txt";
$votes = "Survey.txt";
$dataf =file ($data); /* read out the items in the survey project file */
$file _votes=fopen ($votes, "R");
$line _votes=fgets ($file _votes, 255); /* Read the results of the survey already recorded */
Fclose ($file _votes);
$single _vote=explode ("|", $line _votes); /* and cut the data into the specified string, then pass the string back to the array variable */
if ($result!=1)/* If the investigation has been accepted */
{
$file _votes=file ($votes, "R");
if ($REMOTE _addr = = $file _votes[1])/* Check is not the same person */
{
echo " You have voted, thank you for your participation! ";
Exit
}
/* If IP is not duplicated, execute the following program */
http://www.bkjia.com/PHPjc/445093.html www.bkjia.com true http://www.bkjia.com/PHPjc/445093.html techarticle This is a simple voting procedure, for just learning PHP and friends is a very good entry program. Here to introduce you, hope to be helpful to friends. The system is ...