Ucenter源碼解析--frame.php

來源:互聯網
上載者:User

標籤:

/control/admin/frame.php的流程結構類似於這樣:/control/admin/frame.php -->調用父類adminbase的建構函式,(/model/adminbase的執行個體)-->adminbase類的建構函式,調用父類base類的建構函式(/model/base.php),真正幹活的是base類的建構函式,所以,我們直接看base類的建構函式都實現了什麼。

//建構函式
function __construct() {
$this->base();
}
//base函數
function base() {
//調用內建函式,
$this->init_var();
//初始化資料庫和串連資料庫資訊
$this->init_db();
//引入//data/cache下面的檔案,並載入全部的應用資訊
$this->init_cache();
//初始化所用的應用ID
$this->init_app();
//初始化使用者資訊
$this->init_user();
$this->init_template();
//發送通知函數
$this->init_note();
$this->init_mail();
//$this->cron();
}

可以看到,base乾的話有:

  • 初始化成員變數onlineip,lang
  • 建立資料庫連接
  • 將需要的資料表中的資訊寫到/data/cache對應的檔案,可以說,你在/data/cache/目錄下面看到的內容都是對應的表格中的資料,這樣以來就可以提高代碼效率。不需要重複讀寫資料庫
  • 從上一步中的/data/cache/apps.php檔案中讀取對應的appid內容
  • 讀取瀏覽器的cookie,使用/data/cache/apps.php檔案中讀取出對應appid的密鑰,解密cookie,然後解出userid,username
  • 設定預設主題
  • 使用fsock()向各個應用發生通知
  • 發生email

這個是base的建構函式的功能,adminbase類調用完父類的建構函式,就會執行頁面的載入,我們可以看代碼:

function adminbase() {

//調用父類的建構函式

parent::__construct();

$this->cookie_status = isset($_COOKIE[‘sid‘]) ? 1 : 0;

$sid = $this->cookie_status ? getgpc(‘sid‘, ‘C‘) : rawurlencode(getgpc(‘sid‘, ‘R‘));

$this->view->sid = $sid;

$this->view->assign(‘sid‘, $this->view->sid);

$this->view->assign(‘iframe‘, getgpc(‘iframe‘));

$a = getgpc(‘a‘);

if(getgpc(‘m‘) !=‘user‘ && $a != ‘login‘ && $a != ‘logout‘) {

$this->check_priv();

}

}

執行了父類的建構函式,就會執行自己的check_priv(),check_prive()的函數代碼如下 :

$username = $this->sid_decode($this->view->sid);

if(empty($username)) {

header(‘Location: ‘.UC_API.‘/admin.php?m=user&a=login&iframe=‘.getgpc(‘iframe‘, ‘G‘).($this->cookie_status ? ‘‘ : ‘&sid=‘.$this->view->sid));
exit;

這是部分代碼,所以,第一次進ucenter出現 的登陸介面,就是這個函數實現。我們看地址欄的url:http://ucenter.xadieu.com/admin.php?m=user&a=login&iframe=&sid=

是不是一樣的。所以,我們看到了登陸介面。下一篇,我們會對base.php的建構函式做一個詳細介紹。

 

Ucenter源碼解析--frame.php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.