セッションに問題があります。破壊ではありません。前のページに戻ると、セッションがまだ残っています。
私のコードを見てください:
user_model.php - モデル
<?php
class User_Model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
function login($username, $password)
{
$this->db->where("username", $username);
$this->db->where("password", $password);
$query=$this->db->get("users");
if($query->num_rows()>0)
{
foreach($query->result() as $rows)
{
//add all data to session
$newdata = array(
//'user_id' => $rows->id,
'username' => $rows->username,
'logged_in' => TRUE
);
}
$this->session->set_userdata($newdata);
return true;
}
return false;
}
public function add_user()
{
$data=array(
'username'=> $this->input->post('username'),
'password'=> $this->input->post('password')// md5($this->input->post('password'))
);
$this->db->insert('users',$data);
}
}
?>
user.php - コントローラー
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
}
public function index()
{
if(($this->session->userdata('username') != "" ))
{
$this->welcome();
}
else {
$data['title']= 'Home';
$this->load->view('include/header',$data);
$this->load->view("frontpage", $data);
$this->load->view('include/footer',$data);
}
}
public function welcome()
{
$data['title']= 'Welcome';
$this->load->view('include/header', $data);
$this->load->view('include/navbar', $data);
$this->load->view('welcome_view', $data);
$this->load->view('include/sidebar', $data);
$this->load->view('include/ftr', $data);
$this->load->view('include/footer', $data);
}
public function login()
{
$username = $this->input->post('username');
$password = $this->input->post('password'); // md5($this->input->post('password'));
$result = $this->user_model->login($username, $password);
if($result)
$this->welcome();
else
$this->index();
}
public function thank()
{
$data['title']= 'Thank';
$this->load->view('include/header',$data);
$this->load->view('thank_view.php', $data);
$this->load->view('include/footer',$data);
}
public function registration()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
$this->form_validation->set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');
if($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$this->user_model->add_user();
$this->thank();
}
}
public function logout()
{
$newdata = array(
//'user_id' =>'',
'username' => '',
'logged_in' => FALSE
);
$this->session->unset_userdata($newdata);
$this->session->sess_destroy();
$this->index();
}
}
?>
これらのコードの何が問題なのかわかりません。誰が私に何が悪いのか指摘できますか? 私は本当にあなたの助けが必要です。ありがとう。