CodeInterger中hook 應用場景
阿新 • • 發佈:2017-08-18
hook 登錄驗證
用於後臺登錄驗證
post_controller_constructor
<?php class Auth { private $CI; private $loginUri = ‘welcome/login‘; private $loginAuth = FALSE; private $sessId = null; public function __construct(){ $this->CI = &get_instance(); $this->CI->load->helper(‘url‘); $this->initSession(); $this->setLoginAuth(); } public function initSession(){ if(session_status()===1){ session_name(SESS_NAME); if($this->sessId!==null){ session_id($this->sessId); } $lifeTime = 24 * 3600; session_set_cookie_params($lifeTime); session_start(); } } public function setLoginAuth(){ if(!empty($_SESSION[‘admin_user_id‘])){ $this->loginAuth = TRUE; } } public function chkLoginAuth(){ if(!$this->loginAuth && !in_array(uri_string(),array(‘login‘, ‘login/ajaxsub‘))){ redirect($this->loginUri); } return TRUE; } }
本文出自 “水滴石穿” 博客,請務必保留此出處http://liangge.blog.51cto.com/7154562/1957417
CodeInterger中hook 應用場景