PHP-PHP source code

Source: Internet
Author: User
Ec (2); head & gt; & lt; title & gt; survey & lt; title & gt; & lt; head & gt; & lt; body & gt; & lt; forpolichod & quot; POST & quot; action & quot; survey. php & quot; & gt; & nbsp; & lt; p & gt; & lt; inputtype & quot; radio & quot; script ec (2); script

Head>
Survey





The survey items in the survey file data.txt must be consistent with the number and order of the above survey items. Otherwise, errors may occur or the survey results may be inaccurate. At the same time, in order to display the survey results in a bar chart, we should prepare several bar images of different colors. For example, 0.gif,1.gif,2.gif,3.gif,4.gif.
The following is the survey. php code that implements the investigation function:

Reference content is as follows:
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 user 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 project selected */Chinaz.com

Single_vote + = 1;
}
Fputs (ficdest, "single_vote |");/* write data back to the file */
}
Fputs (ficdest, "\ nREMOTE_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;}For (I = 0; I <= count (dataf)-1; I ++){Imag = strval (I). ". gif";/* determine which bar image is used to display the statistical result */Stat = single_vote/tot_votes * 100;/* calculate the percentage */Scla = stat * 5;/* bar chart and magnification, which is displayed by the width of the prime factor 5 times of the security percentage */Echo" ";}Echo"
  • ";
    Echo "dataf
  • ";
    Echo "";/* output bar code */
    Printf ("%. 1f", "stat ");
    Echo "%
    ";
    /* Output the number of votes in this topic */
    Echo "single_vote ";
    Echo"

    ";
    Echo "total votes: tot_votes ";
    }
    ?>

    Note:
    Here, to prevent one-man multi-vote from being implemented by recording the IP address of the most recent voter, the most recent voting IP address is stored in the environment variable REMOTE_ADDR when the WEB Client sends a request to the server.

    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.