我今天的問題是這樣的。成功登錄後,我想在重定向時將數據陣列中的user_id發送到控制面板。我在這裏有很多代碼。其中98%的代碼是從認證庫中寫入的,我擔心如果我現在修補得太多,現在我最終會通過嘗試做一件事來破壞別的東西。任何幫助?爲重定向添加數據數組
class Auth extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('security');
$this->load->library('tank_auth');
$this->lang->load('tank_auth');
if ($this->tank_auth->is_logged_in()) {
redirect('/cpanel/');
} else {
redirect('/auth/login/');
}
}
function index()
{
}
/**
* Login user on the site
*
* @return void
*/
function login()
{
if ($this->tank_auth->is_logged_in()) { // logged in
redirect('/cpanel');
} elseif ($this->tank_auth->is_logged_in(FALSE)) { // logged in, not activated
redirect('/auth/send_again/');
} else {
$data['login_by_username'] = ($this->config->item('login_by_username', 'tank_auth') AND
$this->config->item('use_username', 'tank_auth'));
$data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth');
$this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
$this->form_validation->set_rules('remember', 'Remember me', 'integer');
// Get login for counting attempts to login
if ($this->config->item('login_count_attempts', 'tank_auth') AND
($login = $this->input->post('login'))) {
$login = $this->security->xss_clean($login);
} else {
$login = '';
}
$data['errors'] = array();
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('/cpanel');
} else {
$errors = $this->tank_auth->get_error_message();
if (isset($errors['banned'])) { // banned user
$this->_show_message($this->lang->line('auth_message_banned').' '.$errors['banned']);
} elseif (isset($errors['not_activated'])) { // not activated user
redirect('/auth/send_again/');
} else { // fail
foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v);
}
}
}
$this->template->set_layout('default')->enable_parser(false);
$this->template->build('auth/login_form', $data);
}
}
編輯:
用下面的代碼,當我去我的kansasoutlawwrestling.com/kowmanager頁我得到一個白色的屏幕,但如果我去我的登錄頁面,這是kansasoutlawwrestling.com/kowmanager/login和登錄然後我得到一個PHP錯誤遇到
嚴重性:注意
消息:未定義的變量:ID
文件名:控制器/ auth.php
行號:63 一個PHP錯誤遇到
嚴重性:警告
消息:無法修改標題信息 - 頭已經發出(輸出開始/家庭/ xtremer /的public_html /系統/核心/ Exceptions.php:170)
文件名:助手/ url_helper.php
行號:543
class Auth extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->library('security');
$this->load->library('tank_auth');
$this->lang->load('tank_auth');
$id = $this->tank_auth->get_user_id();
}
function index()
{
}
/**
* Login user on the site
*
* @return void
*/
function login()
{
if ($this->tank_auth->is_logged_in()) { // logged in
redirect('/cpanel', $id);
} elseif ($this->tank_auth->is_logged_in(FALSE)) { // logged in, not activated
redirect('/auth/send_again/');
} else {
$data['login_by_username'] = ($this->config->item('login_by_username', 'tank_auth') AND
$this->config->item('use_username', 'tank_auth'));
$data['login_by_email'] = $this->config->item('login_by_email', 'tank_auth');
$this->form_validation->set_rules('login', 'Login', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
$this->form_validation->set_rules('remember', 'Remember me', 'integer');
// Get login for counting attempts to login
if ($this->config->item('login_count_attempts', 'tank_auth') AND
($login = $this->input->post('login'))) {
$login = $this->security->xss_clean($login);
} else {
$login = '';
}
$data['errors'] = array();
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('/cpanel', $id);
} else {
$errors = $this->tank_auth->get_error_message();
if (isset($errors['banned'])) { // banned user
$this->_show_message($this->lang->line('auth_message_banned').' '.$errors['banned']);
} elseif (isset($errors['not_activated'])) { // not activated user
redirect('/auth/send_again/');
} else { // fail
foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v);
}
}
}
$this->template->set_layout('default')->enable_parser(false);
$this->template->build('auth/login_form', $data);
}
}
刪除代碼中的歡迎消息? –
當我登錄後,我得到這個:嗨,[我的屏幕名稱在這裏]!您現在登錄。用註銷鏈接。而不是它顯示我希望它去管理控制器我沒有看到它告訴它加載歡迎消息 –
想到的一個想法是在您的項目中的所有文件中搜索句子 - 它往往最快的方式 –