No need for database online voting to investigate php code _ php instances

Source: Internet
Author: User
Tags string back code chart
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" 
  
  • "; 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" 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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.