realization Function: The statistic display of article view quantity
The implementation of the detailed: the total number of views on the article, the current day views, when the weekly views, the monthly view of the volume of statistics
Implementation code location:coreframe/app/content/stat.php
detailed code for the implementation :
1<?PHP2 // +----------------------------------------------------------------------3 /**4 * Content Module Access Statistics5 */6 defined(' In_wz ') orExit(' No Direct script access allowed ');7 $db= Load_class (' db ');8 $formdata=Array();9 $formdata[' id '] =isset($GLOBALS[' ID ']) ?intval($GLOBALS[' ID ']) :Exit('-1 '));Ten $formdata[' cid '] =isset($GLOBALS[' CID ']) ?intval($GLOBALS[' CID ']) :Exit('-2 ')); One if(!$formdata[' ID '] | | !$formdata[' CID '])Exit('-3 ')); A $formdata[' addtime '] =Sys_time; - $formdata[' IP '] =get_ip (); - the $qkey= Get_cookie (' Qkey '); - if($qkey= = "') { - $formdata[' qkey '] =uniqid();//13-bit unique value, obtained from the cookie and written to record Uvs and PV - $lefttime= sys_time+2592000; +Set_cookie (' Qkey ',$formdata[' Qkey '],$lefttime); -}Else { + $formdata[' qkey '] =$qkey; A } at - $db->insert (' Content_stat ',$formdata); - - $r=$db->get_one (' Content_rank ',Array(' cid ' =$formdata[' CID '], ' id ' = =$formdata[' ID '])); - if(!$r) { - $db->insert (' Content_rank ',Array(' cid ' =$formdata[' CID '], ' id ' = =$formdata[' ID '])); in $r[' views '] = 0; - } to $views=$r[' views '] + 1; + $yesterdayviews= (Date(' Ymd ',$r[' UpdateTime ']) ==Date(' Ymd ',Strtotime('-1 day ')) ?$r[' Dayviews ']:$r[' Yesterdayviews ']; - $dayviews= (Date(' Ymd ',$r[' UpdateTime ']) ==Date(' Ymd ', sys_time)) ? ($r[' dayviews '] + 1): 1; the $weekviews= (Date(' YW ',$r[' UpdateTime ']) ==Date(' YW ', sys_time)) ? ($r[' weekviews '] + 1): 1; * $monthviews= (Date(' Ym ',$r[' UpdateTime ']) ==Date(' Ym ', sys_time)) ? ($r[' monthviews '] + 1): 1; $ $db _array=Array(' views ' = =$views, ' yesterdayviews ' =$yesterdayviews, ' dayviews ' =$dayviews, ' weekviews ' =$weekviews, ' monthviews ' =$monthviews, ' updatetime ' =sys_time);Panax Notoginseng - $db->update (' Content_rank ',$db _array,Array(' cid ' =$formdata[' CID '], ' id ' = =$formdata[' ID '])); the + A Echo' $ ("#hits"). html ('.$views.‘)‘; the?>
Database structure:
DROP TABLE IF EXISTS' Wz_content_rank ';CREATE TABLE' Wz_content_rank ' (' CID ' Mediumint (Ten) unsigned not NULL, ' id 'int(Ten) unsigned not NULL DEFAULT '0', ' views 'int(Ten) unsigned not NULL DEFAULT '0', ' yesterdayviews 'int(Ten) unsigned not NULL DEFAULT '0', ' dayviews 'int(Ten) unsigned not NULL DEFAULT '0', ' weekviews 'int(Ten) unsigned not NULL DEFAULT '0', ' monthviews 'int(Ten) unsigned not NULL DEFAULT '0', ' UpdateTime 'int(Ten) unsigned not NULL DEFAULT '0', UNIQUE KEY' CID ' (' CID ', ' id '),KEY"views" (' views ')) ENGINE=MyISAMDEFAULTCHARSET=UTF8;
Load mode:
Content page Invoke JS code
<script type= "Text/javascript" src= "{weburl}index.php?f=stat.php" ></script>
Show article views
<id= "hit"> show views here </span>
Note: The jquery framework needs to be introduced into the page.
How to implement content view of CMS in the fingers