Location: PHPKode > scripts > Easy poll > index.php
<?php
/* ########################## INFO ##########################

                           Easy poll
                          Version 1.0

         Free script from WB - Webdesign for beginners.
          Visit http://plohni.com/wb for more scripts.
               Feel free to modify this script.
                              lgp

/* ########################## INFO ########################## */
/* ###################### INSTALLATION ###################### */

   // a) Adjust the configuration variables to your needs

         $file = "votes.txt"; // Name of the file which
                              // contains the number of
                              // votes
         $title = "What do you think about this site?"; // Title
                                                        // of
                                                        // the
                                                        // poll
         $answers = array("Awesome!",         // Possible
                          "Well, it's ok.",   // answers
                          "Could be better.",
                          "Awful...");

   // b) Copy this code to your PHP file
   // c) Copy your PHP file and the votes file defined in
   //    variable $file to your server using ASCII mode
   // d) Make the votes file writable (Windows: adjust
   //    security, Unix: chmod 777)

/* ###################### INSTALLATION ###################### */
/* ############# SCRIPT (EDIT AT YOUR OWN RISK) ############# */
?>
<h3><?php echo $title; ?></h3>
<p>
  <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<?php
  //print possible answers
  for($i=0;$i<count($answers);$i++){
    ?><input type="radio" name="vote" value="<?php echo $i; ?>"> <?php echo $answers[$i]; ?><br /><?php
  }
?>
    <p><input type="submit" value="Vote!"></p>
  </form>
</p>
<h3>Results</h3>
<p>
<?php
  //read votes
  $votes = file($file);
  $total = 0;
  $vote = $_POST["vote"];

  //submit vote
  if(isset($vote)){
    $votes[$vote] = $votes[$vote]+1;
  }

  //write votes
  $handle = fopen($file,"w");

  foreach($votes as $v){
    $total += $v;
    fputs($handle,chop($v)."\n");
  }

  fclose($handle);

  //print votes
  for($i=0;$i<count($answers);$i++){
    echo "{$votes[$i]} {$answers[$i]}<br />";
  }
?>
</p>
<p>Total: <?php echo $total; ?> votes.</p>
Return current item: Easy poll