這段代碼如何加?

來源:互聯網
上載者:User
本題是關於php做的cms管理系統discuz的問題,所以回答本題要搞過discuz的人.
問題是這樣:我想把系統內建的尾部統計線上人數的代碼放在頭部,所以我就複製了這段代碼到頭部中,但是奇怪的是顯示為亂碼,起碼以為是條件判斷的原因,後來多次檢查,感覺不是.
下面的代碼我是我複製的,不知為啥放在head.htm中就是不行呢,應該如何寫才是正確的呢?

{lang onlinemember}- $onlinenum {lang onlines}- $membercount {lang index_members}($invisiblecount {lang index_invisibles}),$guestcount {lang index_guests}- {lang index_mostonlines} $onlineinfo[0] {lang on} $onlineinfo[1].

{lang onlinemember}{lang onlinemember}- {lang total} $onlinenum {lang onlines}- $membercount {lang index_members},$guestcount {lang index_guests}- {lang index_mostonlines} $onlineinfo[0] {lang on} $onlineinfo[1].

$_G[cache][onlinelist][legend]
  • $online[username]$online[username]
  • {lang online_only_guests}


回複討論(解決方案)

是複製上面代碼後的結果

清緩衝看看。

清緩衝看看。


請緩衝這是最起碼的常識吧!

統計線上人數,那是首頁的功能,如:$onlinenum,$invisiblecount等,都是在\source\module\forum\forum_index.php裡面定義的
而header.htm是所有頁面都要引用的,裡面的變數都是在初始化的時候取出放到了$_G裡面,所以,你直接copy的代碼不生效
有兩種辦法:
1>在source\class\discuz\discuz_application.php中初始化的時候查詢資料庫,並放到$_G中(不建議新手這樣做)
2>在header.htm中調用一個函數,如:,getnolineinfo()方法在source\function\function_core.php中自己定義,裡面具體的實現代碼,請參考source\module\forum\forum_index.php中178行左右的if裡面的代碼

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.