Head>
<title>survey</title>
<body>
<form method= "POST" action= "survey.php" >
<p><input type= "Radio" value= "0" name= "vote" > Investigation Project One </p>
<p><input type= "Radio" name= "Vote" value= "1" > Survey Items two </p>
<p><input type= " Radio "Name=" Vote "value=" 2 "> Research project three </p>
<p><input type=" Radio "name=" Vote "value=" 3 "> Survey item four </P>
<p><input type= "Radio" name= "Vote" value= "4" > Survey items five </p>
<p ><input type= "hidden" name= "Go" value= "1" >
<p><input type= "Submit" value= "submitted" name= "B1" ></p>
<a href= "survey.php?result=1" > View results </a>
</form>
</body >
Note that the survey items in the file data.txt must be consistent with the number and arrangement of the above survey items, or they may be wrong or the results of the investigation will not be accurate. In order to display the survey results in a bar chart, you should prepare a number of different color bar pictures. such as: 0.gif,1.gif,2.gif,3.gif,4.gif and so on.
The following is the survey.php code to implement the survey function:
The following are the referenced contents:
?
Data= "Data.txt";
Votes= "Survey.txt";
Dataf=file (data); /* Read the items in the survey project document * *
File_votes=fopen (votes, "R");
Line_votes=fgets (file_votes, 255); * * read out the results of the investigation as recorded.
Fclose (file_votes);
Single_vote=explode ("|", line_votes); /* and the data is cut into the specified string, then the string is passed 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 "<center><font color=red> you have voted, thank you for your participation!" </font></center> ";
Exit
}
/* If IP does not repeat, execute the following procedure * *
Ficdest=fopen (votes, "w");
For (i=0 I<=count (DATAF)-1; i++)
{
if (i = = vote)
{/* Determine which item is selected/* chinaz.com
Single_vote+=1;
}
Fputs (Ficdest, "single_vote|"); /* Write data back to File/*
}
Fputs (Ficdest, "\nremote_addr");///written to voters ip*/
Fclose (ficdest);
Result=1; * * Voted successfully * *
}
* * Write the results of the poll and show the result of the poll
if (result==1)
{
echo "<table cellpadding=10>";
For (i=0 I<=count (DATAF)-1; i++)
{
* * Get Total votes
Tot_votes+=single_vote;
}
For (i=0 I<=count (DATAF)-1; i++)
{
Imag=strval (i). ". GIF ";/* determine which bar picture to use to display statistical results. *
stat=single_vote/tot_votes*100; /* percent Calculated * *
scla=stat*5;/* bar chart and magnification, here is 5 times times the width of the phase element of the Ann percentage to show the
echo "<tr><td><li><font Face=verdana size=2>";
echo "Dataf</font></td><td Align=left><font face=verdana size=2>";
echo "printf ("%.1f", "stat");
echo "%</font></td><td Align=center><font face=verdana size=2>";
/* Output the number of votes in this column * *
echo "Single_vote</font>";
echo "</td></tr>";
}
echo "</table><p>";
echo "<font Face=verdana size=2> Total votes: tot_votes </font>";
}
?>
Description
In order to prevent a single person from being cast is implemented by recording the IP of the nearest voter, and the most recent one is that the Web client is stored in the environment variable REMOTE_ADDR when making a request to the server.