2005
10.22
10.22
Poll Plugin for WordPress是个比较不错的可以在wordpress里面轻松添加和修改poll投票的插件,(插件主页见这里 http://www.phpaddons.com/poll-plugin-for-wordpress/,当前版本到了1.0.1)今天天发现了一个bug,就是站点里面有多个投票的时候或者您在自己的测试站点里面测试的post的ID和实际运行的站点的相同ID下有投票,当一个有过投票操作后,另外一个就会永远投票失败,也没有错误提示,这个问题主要是因为它采用了COOKIE来处理和记录用户投票操作记录。下面是我解决的办法。
下面这段源代码是作者的原始代码:(在作者源程序的131行开始)
<?php
if (!empty($_COOKIE['padd_poll_voted_posts'])) {
$voted_posts = unserialize(stripslashes($_COOKIE['padd_poll_voted_posts']));
if (in_array($id, $voted_posts)) {
$showResult = true;
}
} elseif (!empty($_POST['padd_poll_view_result'])) {
$showResult = true;
} elseif (!empty($_POST['padd_poll_vote'])) {
$showResult = true;
padd_poll_cast_vote($id, $_POST['padd_poll_vote']);
} else {
$showResult = false;
}
if (!empty($_COOKIE['padd_poll_voted_posts'])) {
$voted_posts = unserialize(stripslashes($_COOKIE['padd_poll_voted_posts']));
if (in_array($id, $voted_posts)) {
$showResult = true;
}
} elseif (!empty($_POST['padd_poll_view_result'])) {
$showResult = true;
} elseif (!empty($_POST['padd_poll_vote'])) {
$showResult = true;
padd_poll_cast_vote($id, $_POST['padd_poll_vote']);
} else {
$showResult = false;
}
下面这段是我修改后的代码:
<?php
if (!empty($_COOKIE['padd_poll_voted_posts'])) {
$voted_posts = unserialize(stripslashes($_COOKIE['padd_poll_voted_posts']));
if (in_array($id, $voted_posts)) {
$showResult = true;
}
}
if (!$showResult){
if (!empty($_POST['padd_poll_view_result'])) {
$showResult = true;
} elseif (!empty($_POST['padd_poll_vote'])) {
$showResult = true;
padd_poll_cast_vote($id, $_POST['padd_poll_vote']);
} else {
$showResult = false;
}
}
if (!empty($_COOKIE['padd_poll_voted_posts'])) {
$voted_posts = unserialize(stripslashes($_COOKIE['padd_poll_voted_posts']));
if (in_array($id, $voted_posts)) {
$showResult = true;
}
}
if (!$showResult){
if (!empty($_POST['padd_poll_view_result'])) {
$showResult = true;
} elseif (!empty($_POST['padd_poll_vote'])) {
$showResult = true;
padd_poll_cast_vote($id, $_POST['padd_poll_vote']);
} else {
$showResult = false;
}
}
欢迎交流!WordPress是个不错的Blog软件!
下面是Poll Plugin for WordPress的一个范例,你喜欢这个插件吗?
