title: Create a PHP Poll with just one vote per IP
body: <p>I have an Ajax Poll for my website users, but in our case a user can vote an unlimited number of times after he refreshes the page, and the results are being recorded.</p>
  
  <p>I would like to let users vote just one time from their IP and after they have voted, at page refresh just to show them the results.</p>
  
  <p>Here is the code</p>
  
  <p>The HTML Page:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function getVote(int)
  {
  if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
  else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
  {
  document.getElementById("poll").innerHTML=xmlhttp.responseText;
  }
  }
  xmlhttp.open("GET","poll_vote.php?vote="+int,true);
  xmlhttp.send();
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="poll"&gt;
  &lt;h3&gt;Do you like PHP and AJAX so far?&lt;/h3&gt;
  &lt;form&gt;
  Yes:
  &lt;input type="radio" name="vote" value="0" onclick="getVote(this.value)"&gt;
  &lt;br&gt;No:
  &lt;input type="radio" name="vote" value="1" onclick="getVote(this.value)"&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>The PHP file:</p>
  
  <pre><code>&lt;?php
  $vote = $_REQUEST['vote'];
  
  //get content of textfile
  $filename = "poll_result.txt";
  $content = file($filename);
  
  //put content in array
  $array = explode("||", $content[0]);
  $yes = $array[0];
  $no = $array[1];
  
  if ($vote == 0)
    {
    $yes = $yes + 1;
    }
  if ($vote == 1)
    {
    $no = $no + 1;
    }
  
  //insert votes to txt file
  $insertvote = $yes."||".$no;
  $fp = fopen($filename,"w");
  fputs($fp,$insertvote);
  fclose($fp);
  ?&gt;
  
  &lt;h2&gt;Result:&lt;/h2&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;Yes:&lt;/td&gt;
  &lt;td&gt;
  &lt;img src="poll.gif"
  width='&lt;?php echo(100*round($yes/($no+$yes),2)); ?&gt;'
  height='20'&gt;
  &lt;?php echo(100*round($yes/($no+$yes),2)); ?&gt;%
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;No:&lt;/td&gt;
  &lt;td&gt;
  &lt;img src="poll.gif"
  width='&lt;?php echo(100*round($no/($no+$yes),2)); ?&gt;'
  height='20'&gt;
  &lt;?php echo(100*round($no/($no+$yes),2)); ?&gt;%
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt; 
  </code></pre>
  
  <p>I would like to let users vote just one time from their IP and after they have voted, at page refresh just to show them the results.</p>