This is a simple voting program. It is a good entry-level program for PHP and friends. I would like to introduce you here, hoping to help you.
The system consists of the following four files: survey.txt.data.txtand survey.txt, which are composed of logs and record results. We can create them using NOTEPAD and upload them to the program directory. The file data.txt is stored in the project to be investigated. Note that each project should take up one line while survey.txt can be an empty file without any content.
The Survey.htm code can be as follows:
<Html>
<Head>
<Title> survey </title>
</Head>
<Body>
<Form method = "POST" action = "survey. php">
<P> <input type = "radio" value = "0" name = "vote"> Project 1 </p>
<P> <input type = "radio" name = "vote" value = "1"> Project 2 </p>
<P> <input type = "radio" name = "vote" value = "2"> Project 3 </p>
<P> <input type = "radio" name = "vote" value = "3"> Project 4 </p>
<P> <input type = "radio" name = "vote" value = "4"> Project 5 </p>
<P> <input type = "hidden" name = "go" value = "1">
<P> <input type = "submit" value = "submit" name = "B1"> </p>
<A href = "survey. php? Result = 1 "> View results </a>
</Form>
</Body>
</Html>
The survey items in the document data.txt 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 in 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 that implements the investigation function:
<?
$ Data = "data.txt ";
$ Votes = "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 you have already received the investigation */
{
$ File_votes = file ($ votes, "r ");
If ($ REMOTE_ADDR = $ file_votes [1])/* check whether the same person is the same */
{
Echo "<center> <font color = red> you have voted. Thank you for your participation! </Font> </center> ";
Exit;
}
/* If the IP address is not repeated, execute the following Program */