Home > Article > Backend Development > How do major manufacturers conduct online voting?
On the Internet, we often see various kinds of voting. Today we will take a look at the online voting done by big manufacturers. Friends in need can refer to it.
I was watching Youku today and happened to see a great person on Youku - I am a legendary online voting person. I am very curious about how these big and awesome companies do online voting, so I would like to analyze it here. How does Youku do online voting?
Youku Talent--I am a legend online voting page: http://c.youku.com/niuren
Choose a player at random and you will A floating layer of playback will pop up with the voting button above. After clicking the vote successfully,
will vote again. To remind you: you have already voted, please vote again after an hour! -----It seems that this vote is normal, but these are superficial phenomena.
Using firebug we can find that each vote will trigger an http request.
We can put this http link:
http://minisite.youku.com/pub2/i_am_legend/vote.php?id=XMjc1NzExMzE2&callback=c&i=0.19621988418141467
My first impression is that this is a vote done using getjson method. We put this in In the browser, after refreshing it several times, I found that the data has been increasing by
, , and 689 votes. Is this how I can swipe votes? ?
With curiosity, I opened the page and found the vote count of this contestant:
My first impression was that this was very different from my usual voting. Similar, quickly look for the ajax request file on the list page;
Sure enough, I found it:
http://minisite.youku.com/pub2/i_am_legend/getvote.php?page=1&callback= cc&count=8&i=0.42276474971249034
This is a very typical data returned by the getjson method in jquery
(I use the jquery framework, Youku does not use jq framework, but it turns out to be similar), I found another source code for this request:
function vTpListGet(pg, pz, t){ pg = (pg || 1); pz = (pz || 8); t = (t || false); cc = function(oList, total){ if(oList.length > 0){ var html = ""; for(var i=0;i < oList.length;i++){ html += "<ul class=\"x\">\n"; html += " <li class=\"x_thumb\"><a href=\"javascript:;\" onclick=\"vTpSet('"+oList[i].videoid+"','"+oList[i].title+"');\" title=\""+oList[i].title+"\"><img src=\""+oList[i].thumburl+"\" alt=\""+oList[i].title+"\" /></a></li>\n"; html += " <li class=\"x_title\"><a href=\"javascript:;\" onclick=\"vTpSet('"+oList[i].videoid+"','"+oList[i].title+"');\" title=\""+oList[i].title+"\">"+oList[i].title+"</a></li>\n"; html += " <li class=\"x_data\">票数:<span class=\"num\">"+oList[i].total+"</span></li>\n"; html += " <li class=\"x_btn\"><span class=\"btn\" onclick=\"vTpSet('"+oList[i].videoid+"','"+oList[i].title+"');\"></span></li>\n"; html += "</ul>\n"; } html += "<p class=\"clear\"></p>"; //alert(html); document.getElementById('videosTpList').innerHTML = html; if(t){ //显示分页 max_cnt = pz; var js_pager = new jsPager(); js_pager.init(total, pz, pg, "vTpPager"); document.getElementById('videosTpPager').style.display = ""; document.getElementById('videosTpPager').innerHTML = js_pager.getHtml(); } } }; js_request("http://minisite.youku.com/pub2/i_am_legend/getvote.php?page="+pg+"&callback=cc&count="+pz+"&i=" + Math.random()); }
Let’s look at Youku’s method of limiting frequent voting:
function vTp(vid){ c = function(num,vid){ alert("投票成功,目前票数为:"+num+"票!"); var exp = new Date (); exp.setTime(exp.getTime() + 3600000); setCookie("nrtp", "true", exp); } if(getCookie("nrtp") != "true"){ js_request("http://minisite.youku.com/pub2/i_am_legend/vote.php?id="+vid+"&callback=c&i=" + Math.random()); }else{ alert("一小时内只能投票一次!"); return false; } }
actually writes cookies on the client side Judging, I can’t help but feel a little bit cheated. In the past, we often got swiped votes when doing online voting, but after all, we are using server-side verification and recording IP to limit it. However, Youku’s voting is completely based on client-side verification.
The data on the list page is displayed in real time, which means it is displayed immediately after voting ---- Our voting that year was also displayed in real time. , but the pressure on the server was too great. When it came to brushing tickets, the database was frequently inserted and read, which put a lot of pressure on the data. The database server often went down. Later, a caching mechanism was used to solve this problem, and the data was displayed after one minute. .
There is something wrong with the voting api file. I put http://minisite.youku.com/pub2/i_am_legend/vote.php?id=XMjc1NzExMzE2&callback=c&i=0.19621988418141467 In the browser, constant refreshing can actually increase the number of votes. Obviously Youku programmers are lazy. They must at least determine the path and method of submitting the page to determine whether it comes from a normal voting request. , if this is the case, this vote will be too easy to swipe votes. Just put this URL in a different F5 of the browser. If it doesn't work, you can just write a js to refresh the page regularly.
The mechanism to prevent ticket fraud is definitely to use client cookies for verification. This is a bit of a novice. The most common method is to verify based on IP (although this method is also used by professional ticket fraud companies. Pediatrics, but still enough to deal with non-professionals) to prevent frequent ticket fraud.
I am a little disappointed. I thought that the technology of big companies is more mature than ours. It seems a bit overestimated. It seems that we should not be blindly obsessed with and Worship big companies, be yourself, and believe in yourself is the key!
Recommended learning: php video tutorial
The above is the detailed content of How do major manufacturers conduct online voting?. For more information, please follow other related articles on the PHP Chinese website!