Codeigniter實(shí)現(xiàn)處理用戶登錄驗(yàn)證后的URL跳轉(zhuǎn)
Codeigniter處理用戶登錄驗(yàn)證后URL跳轉(zhuǎn),主要涉及到了My_Controller.php頁面以及登錄驗(yàn)證模塊User.php頁面,具體代碼如下:
My_Controller.php頁面:
{
public function __construct()
{
parent::__construct();
/*判斷是否登錄,判斷當(dāng)前URL是否是auth/login*/
if ( ! $this->tank_auth->is_logged_in()
&& ( $this->router->fetch_class() != 'auth' && $this->router->fetch_method() != 'login'))
{
$redirect = $this->uri->uri_string();
if ( $_SERVER['QUERY_STRING'])
{
$redirect .= '?' . $_SERVER['QUERY_STRING'];
}
/*跳轉(zhuǎn)到用戶登陸頁面,指定Login后跳轉(zhuǎn)的URL*/
redirect('auth/login?redirect='.$redirect);
}
}
}
User.php頁面:
{
function login()
{
if ($this->tank_auth->is_logged_in()) { // logged in
redirect('/');
} else {
//other codes here......
/*判斷是否有redirect信息*/
$data['redirect'] = isset($_GET['redirect']) ? $_GET['redirect'] : '/';
if ($this->form_validation->run()) { // validation ok
if ($this->tank_auth->login(
$this->form_validation->set_value('login'),
$this->form_validation->set_value('password'),
$this->form_validation->set_value('remember'),
$data['login_by_username'],
$data['login_by_email'])) { // success
redirect($data['redirect']);
} else {
//error handling
}
}
$this->load->view("login_form")
}
}
/*
Note: 在login_form中需要注意,提交表單的form地址:
<?php echo form_open(site_url("/auth/login?redirect=".$redirect)); ?>
*/
}
在login_form中需要注意,提交表單的form地址為:
相關(guān)文章
Codeigniter檢測表單post數(shù)據(jù)的方法
這篇文章主要介紹了Codeigniter檢測表單post數(shù)據(jù)的方法,實(shí)例分析了Codeigniter獲取及檢測post數(shù)據(jù)的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03
Yii操作數(shù)據(jù)庫實(shí)現(xiàn)動(dòng)態(tài)獲取表名的方法
這篇文章主要介紹了Yii操作數(shù)據(jù)庫實(shí)現(xiàn)動(dòng)態(tài)獲取表名的方法,涉及Yii框架針對數(shù)據(jù)庫的動(dòng)態(tài)操作技巧,需要的朋友可以參考下2016-03-03
php AJAX實(shí)例根據(jù)郵編自動(dòng)完成地址信息
當(dāng)客戶輸入一個(gè)POSTCODE后,zipcode.PHP就接收到它,然后進(jìn)行從數(shù)據(jù)表中取出對應(yīng)的資料,再按一定的格式返回給客戶端(此處是以 | 分隔)。最后客戶端接收返回的資料,顯示在頁面上。2008-11-11
laravel 解決強(qiáng)制跳轉(zhuǎn) https的問題
今天小編就為大家分享一篇laravel 解決強(qiáng)制跳轉(zhuǎn) https的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10

