涓篢ypecho澧炲姞鏂囩珷闃呰娆℃暟缁熻鍔熻兘
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了涓篢ypecho澧炲姞鏂囩珷闃呰娆℃暟缁熻鍔熻兘相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/cookie' title='cookie'>cookie exp 闃呰 鏂囩珷 archive operator this index lang
鏂囩珷娆℃暟缁熻鏄瘮杈冨父鐢ㄧ殑鍔熻兘锛屾彃浠朵竴鎼滀竴鍫嗭紝涓嬮潰璇磋鎶婅繖涓姛鑳介泦鎴愬埌涓婚閲岀殑鏂规硶锛?br />鎶婁笅闈㈣繖娈典唬鐮佹斁鍒颁富棰樻枃浠秄unctions.php涓?/p>
function Postviews($archive) {
$db = Typecho_Db::get();
$cid = $archive->cid;
if (!array_key_exists(鈥榲iews鈥?span class="token punctuation">, $db->fetchRow($db->select()->from(鈥榯able.contents鈥?span class="token punctuation">)))) {
$db->query(鈥楢LTER TABLE `鈥?span class="token punctuation">.$db->getPrefix().鈥榗ontents` ADD `views` INT(10) DEFAULT 0;鈥?span class="token punctuation">);
}
$exist = $db->fetchRow($db->select(鈥榲iews鈥?span class="token punctuation">)->from(鈥榯able.contents鈥?span class="token punctuation">)->where(鈥榗id = ?鈥?span class="token punctuation">, $cid))[鈥榲iews鈥?span class="token punctuation">];
if ($archive->is(鈥榮ingle鈥?span class="token punctuation">)) {
$cookie = Typecho_Cookie::get(鈥榗ontents_views鈥?span class="token punctuation">);
$cookie = $cookie ? explode(鈥?鈥?span class="token punctuation">, $cookie) : array();
if (!in_array($cid, $cookie)) {
$db->query($db->update(鈥榯able.contents鈥?span class="token punctuation">)
->rows(array(鈥榲iews鈥?=> (int)$exist+1))
->where(鈥榗id = ?鈥?span class="token punctuation">, $cid));
$exist = (int)$exist+1;
array_push($cookie, $cid);
$cookie = implode(鈥?鈥?span class="token punctuation">, $cookie);
Typecho_Cookie::set(鈥榗ontents_views鈥?span class="token punctuation">, $cookie);
}
}
echo $exist == 0 ? 鈥樻殏鏃犻槄璇烩€?: $exist.鈥?娆¢槄璇烩€?span class="token punctuation">;
}
鐒跺悗鍦ㄩ椤礽ndex.php銆佹枃绔犻〉post.php鎴栬€呭叾浠栭渶瑕佽緭鍑洪槄璇婚噺鐨勪綅缃皟鐢?code><?php Postviews($this); ?>鍗冲彲锛堟枃绔犻〉蹇呴』瑕佽皟鐢紝鍚﹀垯鏃犳硶缁熻锛夈€?/p>
以上是关于涓篢ypecho澧炲姞鏂囩珷闃呰娆℃暟缁熻鍔熻兘的主要内容,如果未能解决你的问题,请参考以下文章
绉嬫嫑鎻愬墠鎵瑰凡鏉ワ紝涓囧瓧闀挎枃鏁欎綘濡備綍澧炲姞闈㈣瘯澶у巶鐨勬垚鍔熺巼馃敟