Php and Ajax voting systems .? Php?vote=_get?vote=%echo=vote=%filenamepoll.txt; $ contentfile ($ filename); read the entire file into an array $ arrexplode (||, $ content [0]); $ yes $ arr [0]; $ no $ arr [1];
$ Vote = $ _ GET ['vote'];
// Echo $ vote;
$ Filename = "poll.txt ";
$ Content = file ($ filename); // read the entire file into an array.
$ Arr = explode ('|', $ content [0]);
$ Yes = $ arr [0];
$ No = $ arr [1];
If ($ vote = 0 ){
$ Yes = $ yes + 1;
}
If ($ vote = 1 ){
$ No = $ no + 1;
}
$ Intpoll = $ yes. "|". $ no;
$ Fp = fopen ($ filename, 'w ');
Fputs ($ fp, $ intpoll );
Fclose ($ fp );
?>
POLL:
Yes: |
Width =' ' Height = '20'> % |
No: |
Width =' ' Height = '20'> % |
// Poll. js
Var xmlHttp
Function GetXmlHTTPObject (){
Var Object = null;
If (window. XMLHttpRequest)
{
Object = new XMLHttpRequest ()
}
Else if (window. ActiveXObject)
{
Object = new ActiveXObject ("Microsoft. XMLHTTP ")
}
Return Object;
}
Function statechang (){
If (xmlHttp. readyState = 4 | xmlHttp. readyState = "complete "){
Document. getElementById ("poll ").
InnerHTML = xmlHttp. responseText;
}
}
Function getVote (int ){
XmlHttp = GetXmlHTTPObject ()
If (xmlHttp = null ){
Alert ('error! ');
Return
}
Var url = "poll. php"
Url = url + "? Vote = "+ int
Url = url + "& sid =" + Math. random ()
XmlHttp. onreadystatechange = statechang
XmlHttp. open ("GET", url, true)
XmlHttp. send (null)
}
// Poll.html
POLL)