1
我有这个功能的网页浏览量计数器:如何使用的setcookie页面浏览量计数器功能
function PageViews($postID) {
$c_key = 'views_count';
$cookie_count = $_COOKIE['views_count_'.$postID];
$count = get_post_meta($postID, $c_key, true);
if(!$cookie_count){
setcookie('views_count_'.$postID , 'view', time()+999999999);
if($count == ''){
$count = 1;
update_post_meta($postID, $c_key, $count);
return $count;
}else{
$count++;
update_post_meta($postID, $c_key, $count);
return $count;
}
}else{
return $count;
}
}
当我去查看后我得到这个错误:
Warning: Cannot modify header information - headers already sent by (output started at....
和我的cookie没有按不设置,此功能在function.php
。如何设置这个cookie?
如何做到这一点? –
@AdamMo。在将任何输出呈现到屏幕之前,您可以通过调用此函数来完成此操作。你没有显示你称之为函数的地方,只是函数定义和错误。从错误消息中可以清楚地看到,在某些输出已发送到屏幕后,您正在调用此功能。 –