[eluser]r0mel[/eluser]
good day everyone,, i need your help guys, I have a problem with my session, when I logout, though it works but still when i press the back button, it still can go through the home page. I want my page go steady in the login form after i press logout. I'am a novice about codeigniter. please hepl me,, you appreciatition with this problem would help a lot.
-->>here is my controller test.php
Code:
<?php if( !defined('BASEPATH') ) exit("No direct access script allowed");
class Test extends CI_Controller {
var $model;
function __construct() {
parent::__construct();
// for session library
$this->load->library( array('session') );
// form helper
$this->load->helper( array('form','url', 'html', 'string') );
// load the test model
$this->load->model("test/testmodel");
// initialize the test model
$this->model = new TestModel();
}
// function name index is a reserved word
function index() {
// echo "te";
if( ! $this->session->userdata('isLogin'))
$this->load->view("test/login", array('hh', 'laur0n'));
}
function check_login() {
$username = $this->input->post('username') ? $this->input->post('username') : '' ;
$password = $this->input->post('password') ? $this->input->post('password') : '' ;
// var_dump( $this->input->post() );
$query = $this->model->authenticate_user( $username, $password);
if( $query ) {
$this->session->set_userdata('isLogin', 'mi agi ko');
redirect("test/test/loginKo");
// echo json_encode( $query );
}
else {
// echo json_encode( $query );
$this->load->view('test/login');
}
}
function register() {
$this->load->view("test/register");
}
public function loginKo(){
// if( gettype( $this->session->userdata('isLogin') ) === "boolean" ) redirect('test/test');
// echo gettype( $this->session->userdata('isLogin') );
if($this->session->userdata("isLogin")){
$this->load->view('test/information');
}else{
redirect("/test/test");
}
}
function save_register() {
$item = array(
'objid' => null,
'firstname'=> $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'gender' => $this->input->post('gender'),
'status' => 'A'
);
if( $this->model->save_user( $item ))
$this->load->view('test/login');
}
function logout() {
$this->session->sess_destroy();
// echo json_encode( $this->session->all_userdata() );
redirect("test/test");
}
}
?>
-->> here is my model
Code:
<?php if( !defined('BASEPATH') ) exit("No direct access script allowed");
class TestModel extends CI_Model {
function __construct() {
parent::__construct();
$this->load->database();
}
function save_user( $item ) {
$query = $this->db->insert('users', $item);
return $query ? 1 : 0;
}
function authenticate_user( $email='', $password='' ) {
$query = "select * from users where email='{$email}' and password='{$password}'";
// echo $query;
$query = $this->db->query( $query );
if( $query->num_rows() > 0 ) {
return $query->result();
}
return false;
}
}
?>
-->> here is my view
Code:
<?php
if( ! $this->session->userdata('isLogin') )
redirect('test/test');
?>
this is the home page
<?php echo anchor('test/test/logout', 'logout'); ?>