1
我有一個問題,我已經登錄頁面登錄,就會直接到配置文件,如果我們輸入了正確的電子郵件&密碼,但問題是,當我改變的URL登錄,它仍然移動到登錄頁面,我怎麼能阻止登錄頁面如果我已經登錄,這樣會dirrect到配置文件儘管該網址我改變它的登錄頁面仍然直接到配置文件頁面。個人資料頁還是移動到登錄頁面,如果我的網址改爲即使已經登錄
下面是代碼:
class Profile extends CI_Controller {
public function index()
{
if($this->session->userdata('logged_in')){
$session_data = $this->session->userdata('logged_in');
$data['email'] = $session_data['email'];
$this->load->view('view_profile', $data);
}else{
redirect('login','refresh');
}
}
public function logout(){
$this->session->unset_userdata('logged_in');
$this->session->sess_destroy();
redirect(site_url('home'),'refresh');
}
}
這是用戶數據( 'LOGGED_IN')
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$this->form_validation->set_rules('email','Email','trim|required');
$this->form_validation->set_rules('password','Password','trim|required|callback_basisdata_cek');
if($this->form_validation->run()==false){
$this->load->view('view_home');
}else{
redirect(base_url('index.php/profile'),'refresh');
}
}
function basisdata_cek($password){
$email = $this->input->post('email');
$result = $this->login->login($email,$password);
if($result){
$sess_array = array();
foreach($result as $row){
$sess_array = $arrayName = array('email'=>$row->email, 'password'=>$row->password);
$this->session->set_userdata('logged_in',$sess_array);
}
return true;
}else{
$this->session->set_flashdata('basisdata_cek', 'Invalid email or password');
redirect(base_url('index.php/login'),'refresh');
return false;
}
}
}
什麼是$這個 - >值session-> userdata('logged_in')? –
@AdhanTimothyYounes有我在編輯的代碼,我把值$這 - >會話級>用戶數據(「LOGGED_IN」) – Firm
可能也許你正在破壞在登錄類第一手會議.... –