&提交;在页面刷新时复制分级数据。
如果只是页面刷新问题,请在表单提交后重定向用户。这将阻止重新提交,因为浏览器当前的请求不是表单提交。快速示例:在表单处理程序中。。。
<?php
// your form handler someplace
// save the rating data.
wp_redirect($page_they_came_from, 303);
exit;
如果需要防止用户多次投票,请在表单处理程序的末尾设置cookie(然后重定向,请参见上文)。
<?php
// you form handler someplace
// save rating data
$voted = isset($_COOKIE[\'_wp_voted\']) ? explode(\',\' $_COOKIE[\'_wp_voted\']) : array();
if(!in_array($the_item_for_voting, $voted))
{
// save votes here.
$voted[] = $the_item_for_voting;
}
setcookie(
\'_wp_voted\',
implode(\',\', $voted),
time() + (60 * 60 *24), // one day
\'/\', // the whole site
COOKIE_DOMAIN, // this is set by WP, or in your wp-config.php
false,
true
);
wp_redirect($page_they_came_from, 303);
exit;