This article describes in detail the php code, which is an online call voting system made by php + txt text files, the online user survey function can be completed without database support. The details are as follows:
Online survey program code // Survey. php <? /* No need for database tutorials online voting investigation php code this is an online call voting system made by php + txt text files. the online user survey function can be completed without the need for database support. */$ 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 by the specified string, then pass the string back to the array variable */if ($ result! = 1)/* if you have received the investigation */{$ file_votes = file ($ votes, "r"); if ($ remote_addr = $ file_votes [1]) /* check whether it is the same person */{echo"
You have already voted. thank you for your participation!
"; Exit;}/* If the ip address is not repeated, execute the following program */$ ficdest = fopen ($ votes," w "); for ($ I = 0; $ I <= count ($ dataf)-1; $ I ++) {if ($ I = $ vote) {/* Determine the selected project */$ single_vote [$ I] + = 1;} fputs ($ ficdest, "$ single_vote [$ I] | "); /* write data back to the file */} fputs ($ ficdest, "n $ remote_addr");/* // write the ip address of the voter */fclose ($ ficdest ); $ result = 1;/* vote successful */}/* write the voting result and display the voting result */if ($ result = 1) {echo"
"; For ($ I = 0; $ I <= count ($ dataf)-1; $ I ++) {/* get the total number of votes */$ tot_votes + = $ single_vote [$ I];} for ($ I = 0; $ I <= count ($ dataf)-1; $ I ++) {$ imag = strval ($ I ). ". gif ";/* determine which bar image is used to display the statistical result */$ stat [$ I] = $ single_vote [$ I]/$ tot_votes * 100; /* calculate the percentage */$ scla = $ stat [$ I] * 5;/* bar chart and magnification, here is the width of the phase Element 5 times of the security percentage to Display */echo"
"; Echo" $ dataf [$ I] |
"; Echo" ";/* output bar code chart */printf (" %. 1f "," $ stat [$ I] "); echo" % |
";/* Output the number of votes in this topic */echo" $ single_vote [$ I] "; echo" |
";} Echo"
"; Echo" Total votes: $ tot_votes ";}/* data.txt file Survey Project 1 Survey Project 2 Survey Project 3 Survey Project 4 Survey Project 5 */?>
The above is all the content of this article. I hope it will be helpful to everyone's learning, and I hope you can support your own home.