本文转自我的博客:(my.unix-center.net/~xiaoshe)
http://my.unix-center.net/~xiaoshe/2010/04/19/%E4%B8%80%E4%B8%AA%E8%B6%85%E7%BA%A7%E7%AE%80%E5%8D%95%E7%9A%84php%E6%8A%95%E7%A5%A8%E7%B3%BB%E7%BB%9F%EF%BC%8C%E4%B8%8D%E4%BD%BF%E7%94%A8%E6%95%B0%E6%8D%AE%E5%BA%93/
从网上发现的一个超级简单的基于php的投票系统,不需要数据库,使用文件来储存投票结果。
参考网页链接:
http://2008.gr0w.com/articles/code/php_5_star_rating_system_using_hreview/index.php
代码如下,其中我加了注释:
< ?
// User settings
$rater_ip_voting_restriction = true; // restrict ip address voting (true or false)
$rater_ip_vote_qty=1; // how many times an ip address can vote
$rater_already_rated_msg="You have already rated this item. You were allowed ".$rater_ip_vote_qty." vote(s).";
$rater_not_selected_msg="You have not selected a rating value.";
$rater_thankyou_msg="Thankyou for voting.";
$rater_generic_text="this item"; // generic item text
$rater_end_of_line_char="\n"; // may want to change for different operating systems
if(!isset($rater_id)) $rater_id=1;
if(!isset($rater_item_name)) $rater_item_name=$rater_generic_text;
// DO NOT MODIFY BELOW THIS LINE
$rater_filename='item_'.$rater_id.".rating";
$rater_rating=0;
$rater_stars="";
$rater_stars_txt="";
$rater_rating=0;
$rater_votes=0;
$rater_msg="";
// Rating action==结果是将投票的结果写入文件中,如果没有submit,则不执行,如果没有评分就submit了,则显示告警信息
if(isset($_REQUEST["rate".$rater_id])){ //判断submit按钮有没有被按下
if(isset($_REQUEST["rating_".$rater_id])){//在此基础上判断用户按下submit按钮时是否没有评分,没有的话则给出一个告警消息
while(list($key,$val)=each($_REQUEST["rating_".$rater_id])){//将用户的评分值存为中间变量rater_rating值,其实觉得没有必要用while的表达式
$rater_rating=$val;
}
$rater_ip = getenv("REMOTE_ADDR");//得到用户的ip
$rate