Ok so I got the W3 Schools Ajax Poll System thing. It works great accept. Someone could sit there all day voting "yes" or "no" and render it usless.
How it works.
Person votes then they see there results. It uses js, php, and good old fashion forms and text. Quite simple.
I was thinking that after the person votes they could no longer vote again. When they refresh the page they see their results.
Heres all the code:
PHP Page which holds the form:
External Js Page which holds the Javascript:HTML Code:<div id="poll"> <form> Yes: <input type="radio" name="vote" value="0" onclick="getVote(this.value)"> <br>No: <input type="radio" name="vote" value="1" onclick="getVote(this.value)"> </form> </div>
The other PHP Page/Code which does all the pretty processing:Code:var xmlHttp function getVote(int) { xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert ("Browser does not support HTTP Request") return } var url="poll_vote.php" url=url+"?vote="+int url=url+"&sid="+Math.random() xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null) } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById("poll"). innerHTML=xmlHttp.responseText; } } function GetXmlHttpObject() { var objXMLHttp=null if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp }
Is there anyway that I could make it so that the person cant vote again to rig the results?PHP Code:<?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);
?><table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>Yes:</td>
<td>
<img src="poll.gif"
width='<?php echo(100*round($yes/($no+$yes),2)); ?>'
height='20'>
<?php echo(100*round($yes/($no+$yes),2)); ?>%
</td>
</tr>
<tr>
<td>No:</td>
<td>
<img src="poll.gif"
width='<?php echo(100*round($no/($no+$yes),2)); ?>'
height='20'>
<?php echo(100*round($no/($no+$yes),2)); ?>%
</td>
</tr>
</table>


Reply With Quote

Bookmarks