This is an online call voting system made up of php + txt text files. online user surveys can be completed without the need for database support. The code is as follows: Copy the code htmlgt; l...
This is an online call voting system made up of php + txt text files. online user surveys can be completed without the need for database support.
The code is as follows: |
|
Online survey program code
|
// Survey. php
The code is as follows: |
|
/* No need for database tutorials online voting for php code
*/ $ 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" 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 a file */ } Fputs ($ ficdest, "$ remote_addr");/* // ip address of the writer */ 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 ++){/* Obtain 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, which are displayed by a pixel width of 5 times of the security percentage */Echo"
"; Echo "$ dataf [$ I] |
"; Echo "";/* output bar code */ 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
Project 1
Project 2
Project 3
Project 4
Project 5
*/
?>
Article address:
Reprint at will ^ please include the address of this article!