本帖最后由 DZ动力1013 于 2014-11-8 13:50 编辑
首先你要把在线人数的模板代码放到想要的模板文件中,模板中的在线代码是以下代码- <div class="bm_h">
- <!--{if $detailstatus}-->
- <span class="o"><a href="forum.php?showoldetails=no#online" title="{lang spread}"><img src="{IMGDIR}/collapsed_no.gif" alt="{lang spread}" /></a></span>
- <h3>
- <strong><a href="home.php?mod=space&do=friend&view=online&type=member">{lang onlinemember}</a></strong>
- <span class="xs1">- <strong>$onlinenum</strong> {lang onlines}
- - <strong>$membercount</strong> {lang index_members}(<strong>$invisiblecount</strong> {lang index_invisibles}),
- <strong>$guestcount</strong> {lang index_guests}
- - {lang index_mostonlines} <strong>$onlineinfo[0]</strong> {lang on} <strong>$onlineinfo[1]</strong>.</span>
- </h3>
- <!--{else}-->
- <!--{if empty($_G['setting']['sessionclose'])}-->
- <span class="o"><a href="forum.php?showoldetails=yes#online" title="{lang spread}"><img src="{IMGDIR}/collapsed_yes.gif" alt="{lang spread}" /></a></span>
- <!--{/if}-->
- <h3>
- <strong>
- <!--{if !empty($_G['setting']['whosonlinestatus'])}-->
- {lang onlinemember}
- <!--{else}-->
- <a href="home.php?mod=space&do=friend&view=online&type=member">{lang onlinemember}</a>
- <!--{/if}-->
- </strong>
- <span class="xs1">- {lang total} <strong>$onlinenum</strong> {lang onlines}
- <!--{if $membercount}-->- <strong>$membercount</strong> {lang index_members},<strong>$guestcount</strong> {lang index_guests}<!--{/if}-->
- - {lang index_mostonlines} <strong>$onlineinfo[0]</strong> {lang on} <strong>$onlineinfo[1]</strong>.</span>
- </h3>
- <!--{/if}-->
- </div>
复制代码
如果是访问的列表或者帖子页还要找到对应的模块程序文件,比如source\module\forum\forum_viewthread.php或者source\module\forum\forum_forumdisplay.php,然后在程序文件中require语句以后添加以下代码才可以调用出数据- $onlineinfo = explode("\t", $_G['cache']['onlinerecord']);
- if(empty($_G['cookie']['onlineusernum'])) {
- $onlinenum = C::app()->session->count();
- if($onlinenum > $onlineinfo[0]) {
- $onlinerecord = "$onlinenum\t".TIMESTAMP;
- C::t('common_setting')->update('onlinerecord', $onlinerecord);
- savecache('onlinerecord', $onlinerecord);
- $onlineinfo = array($onlinenum, TIMESTAMP);
- }
- dsetcookie('onlineusernum', intval($onlinenum), 300);
- } else {
- $onlinenum = intval($_G['cookie']['onlineusernum']);
- }
- $onlineinfo[1] = dgmdate($onlineinfo[1], 'd');
复制代码
这是由于模板里的在线变量要在程序中获取数值后才可以显示在页面中显示出来 |