网络语言中使用的一般技术是什么,允许非注册用户投票?

Com*_*org 2 web-services vote web

我正在寻求理解某些网站使用的一般机制,允许非注册用户或仅仅是客人投票(例如评论,视频,图像等).他们如何跟踪?与此类网站一样,同一客人不能在同一终端投票两次.他们存储他们的IP地址吗?或者他们保存计算机ID /名称?

任何想法都非常感谢.

PS :( mywot.com)就是这类网站的一个例子.

Mat*_*rba 5

他们使用cookie或会话来识别已经投票的计算机.如果您对Javascript或PHP有所了解,我可以举几个例子.

编辑:好的,所以这是一个例子:

<button value="VOTE" onClick="vote();">
<script>
var votes = 9654;  //Some vote counter - only for test purposes - practically, this wouldn't work, the votes would have to be stored somewhere, this number is only stored in the browser and won't actually change for everyone, who sees the page!
function vote()
{
 var cookies = document.cookie.split(";"); //Make an array from the string
 var alreadyVoted = false;
 for (var i = 0; i < cookies.length; i++)  //Iterate through the array
 {
  temp = cookies[i].split("=");
  if (temp[0] == "voted" && temp[1] == "true")  //The cookie is there and it is "true", he voted already
   alreadyVoted = true;
 }
 if (alreadyVoted)
 {
  alert("You can't vote twice, sorry.");
 }
 else
 {
  var date = new Date();
    date.setTime(date.getTime()+(5*24*60*60*1000));  //Cookie will last for five days    (*hours*mins*secs*milisecs)
    var strDate = date.toGMTString();  //Convert to cookie-valid string
  document.cookie = 'voted=true; expires=' + strDate + '; path=/';  //Creating the cookie
  votes++;  //Here would be probably some ajax function to increase the votes number
  alert("Thanks for voting!\nVotes: "+votes);
 }
}
</script>
Run Code Online (Sandbox Code Playgroud)

希望这会有所帮助,但它只是一个非常简单的cookie demnostration代码,实际上不适用于投票!您将不得不使用一些PHP或类似的东西来实际存储投票值...

  • 请提供示例,而不是询问您是否应该:-) (2认同)