Analysis:
We use a file (data.dat) to store the voting columns. Each column occupies one line.
In this way, you can add and subtract the columns you want to vote at will.
We will then Use a file (votes.dat) to store our voting results.
And record the IP address of the latest voter to simply prevent one person from voting more than once.
So, you should create it yourself in the program directory Two files data.dat and votes.dat
Part of the program running process
When the program is running, there should first be a voting HTML form, waiting for voting.
When someone votes on the HTML form, determine its Whether the IP is the IP of the most recent voter,
If this person has just voted, the two values should be equal, showing "You have already voted, thank you for your participation!"
If this person has just voted If you have not voted, the two values are not equal, write its vote to the file (votes.dat)
(The method to get the voter’s IP here is: the Web client needs to provide a table when sending a request to the server
This representation is stored in the environment variable REMOTE_ADDR, we can just reference it.)
Finally, the voting results are displayed. Usually we use "bar chart + percentage" to display the voting situation.
So, we need to choose a rectangular shape with a single color to adapt to the requirements of horizontal scaling.
-------------------------- -------------------------------------------------- ----
The program code part can be downloaded
//The voting column stores the file, you can change the file name
$data="data.dat";
//The voting result storage file
$votes="votes.dat";
//Graphic file name used to display the proportion of voting results,
//It is better to use a single-color rectangle to facilitate horizontal scaling of voting results,
//Upload it to the directory of this program by yourself
$path_img="vote.gif";
//Poll title
$poll_name="Which of my columns do you like?";
// The following parts do not need to be changed //
//Open the voting column file and save all the contents in the variable $dataf in the form of an array for later use.
$dataf=file($data);
if ( $go !=1)
{
//Display voting program form
echo "$poll_name
n";
echo "
"; echo " "; //Output percentage printf("%.1f", "$stat[$i]"); echo "% | < ;td align=center>"; //Output the number of votes in this column
";
echo "Total votes: $tot_votes < /font>";
}
}
?>