2012-03-15 46 views
0

編碼錯誤,我不能夠在http://www.enbloc.sg投票通過限制程序員

正常啓動我的網站。這是因爲我的程序員無法弄清楚的一個問題。任何幫助將非常感激。

訪客通過點擊交通信號燈上的一種顏色進行投票。他們應該只有一票。

該網站首先檢查cookies,然後檢查選民的IP地址。如果2與以前的訪客相同,則不允許投票。如果只重複2箇中的一個,則允許投票。

雙重限制的想法是讓不同的選民支持固定IP進行投票。例如。公司的員工將無法投票,因爲他們可能通過固定的IP地址訪問該網站。

但是,目前,訪問者可以點擊所有3種顏色在他們第一次訪問該網站時註冊3票。我的編碼器無法解決這個問題,並且拋棄了我。

如果有人能幫忙,我將不勝感激。我相信下面附有相關的代碼。

道歉,如果我的發佈格式錯誤。

非常感謝, 林恩

http://www.enbloc.sg/js/functions.js

//update dashboard when vote by user 
function vote_update(ip_address, issue_num, vote_status){ 
    var vote_cookie = document.getElementById('vote_cookie').value; 
    if(vote_cookie != '') 
    { 
       if(document.getElementById('thanks').style.display  == "none") 
        { 
         $("#multi_error").fadeIn("slow"); 
        } 
        else 
        { 
          document.getElementById("thanks").style.display = "none"; 
         $("#multi_error").fadeIn("slow"); 
        } 
    } 
    else 
    { 
     if(ip_address != ' ' && issue_num != ' ') 
     { 
     http.open("POST", "update_vote.php"); // true 
     http.onreadystatechange = update_vote; 
     http.setRequestHeader("Content-Type", "application/x-www-form- urlencoded;charset=UTF-8"); 
     http.send("ip="+ ip_address +"&issue_num="+ issue_num + "&vote_status=" +  vote_status); 
     } 
     else 
     { 
     alert("Occur Error for IP or ISSUE!"); 
     } 
    } 
} 

// ajax response function 
function update_vote(){ 
    if (http.readyState == 4) 
    { 
     if (http.status == 200) 
     { 
      var xmlDoc = http.responseXML; 
      var listElements = xmlDoc.getElementsByTagName("list"); 
      var result = listElements[0].getElementsByTagName("total") [0].childNodes[0].nodeValue; 
      if (result == 1) 
      { 

       var issue_num =  listElements[0].getElementsByTagName("issue")[0].childNodes[0].nodeValue; 
       var vote = listElements[0].getElementsByTagName("vote") [0].childNodes[0].nodeValue; 
        $("#thanks").fadeIn("slow"); 

       load(issue_num, vote); 
      } 
      else if (result == 'Multi') 
      { 
       if(document.getElementById('thanks').style.display ==  "none") 
       { 
        $("#multi_error").fadeIn("slow"); 
       } 
       else 
       { 
        document.getElementById("thanks").style.display =  "none"; 
        $("#multi_error").fadeIn("slow"); 
       } 

      } 
      else 
      { 
       alert("error"); 
      } 
     } 
    } 
} 

回答

0

提取這些變化將有助於:

var already_voted = false; 

function vote_update(ip_address, issue_num, vote_status) 
{ 
    if(alread_voted) return; 
    already_voted = true; 

    // rest of the code 
} 

這將確保只有一票可以在一個被投單次訪問。餅乾照顧其餘,並已正常工作。