Codeigniter實現(xiàn)處理用戶登錄驗證后的URL跳轉(zhuǎn)
Codeigniter處理用戶登錄驗證后URL跳轉(zhuǎn),主要涉及到了My_Controller.php頁面以及登錄驗證模塊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)文章
在 Laravel 項目中使用 webpack-encore的方法
這篇文章主要介紹了在 Laravel 項目中使用 webpack-encore的方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07PHP實現(xiàn)AJAX動態(tài)網(wǎng)頁及相關(guān)函數(shù)詳解
ajax其實是利用javascript向服務(wù)器請求數(shù)據(jù),然后局部修改頁面,下面這篇文章主要給大家介紹了關(guān)于PHP實現(xiàn)AJAX動態(tài)網(wǎng)頁及相關(guān)函數(shù)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-08-08Laravel5中實現(xiàn)模糊匹配加多條件查詢功能的方法
這篇文章主要介紹了Laravel5中實現(xiàn)模糊匹配加多條件查詢功能的方法,結(jié)合實例形式分析了Laravel5多條件模糊查詢及相關(guān)封裝操作技巧,需要的朋友可以參考下2018-03-03PHP strcmp()和strcasecmp()的區(qū)別實例
這篇文章主要介紹了PHP strcmp()和strcasecmp()的區(qū)別實例的相關(guān)資料,需要的朋友可以參考下2016-11-11Laravel基礎(chǔ)_關(guān)于view共享數(shù)據(jù)的示例講解
今天小編就為大家分享一篇Laravel基礎(chǔ)_關(guān)于view共享數(shù)據(jù)的示例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10