Code has been added to clipboard!

Requesting Servers With AJAX Polling

Example
<?php
  $res = $_REQUEST['res'];

  //get content of the text file
  $file_name = 'poll_result.txt';
  $content = file($file_name);

  //put content in an array
  $arr = explode('||', $content[0]);
  $y = $arr[0];
  $n = $arr[1];

  if ($res == 0) {
    $y = $y + 1;
  }
  if ($res == 1) {
    $n = $n + 1;
  }

  //insert votes into text the file
  $insert_vote = $y."||".$n;
  $fp = fopen($file_name, 'w');
  fputs($fp,$insert_vote);
  fclose($fp);
?>

<h2>Results:</h2>
<table>
  <tr>
    <td>Yes!:
      <img src="poll_results.png"
      width='<?php echo(200*round($y/($n+$y),2)); ?>'
      height='20'>
      <?php echo(200*round($y/($n+$y),2)); ?>%
    </td>
  </tr>
  <tr>
    <td>No!:
      <img src='poll_results.png'
      width='<?php echo(200*round($n/($n+$y),2)); ?>'
      height='20'>
      <?php echo(200*round($n/($n+$y),2)); ?>%
    </td>
  </tr>
</table>