Note that there are some explanatory texts on larger screens.

plurals
  1. POcodeigniter sess_destroy() not working properly,what m i doing wrong?
    primarykey
    data
    text
    <p>I am a newbie in codeigniter. I am using an an login form to login as an admin. When the admin logs in with the correct user name and password s/he is directed to the home page with a session variable.and then if he clicks the log out button the session is supposed to be destroyed and redirect the user to log in page i.e log in form page.</p> <p>The 1st controller is admin:</p> <pre><code>&lt;?php class Admin extends CI_Controller { function index() { $data['main_content'] = 'admin/log_in'; $this -&gt; load -&gt; view('includes/admin/admin_template', $data); } function log_in() { $this-&gt;load-&gt;model('admin_model'); $query = $this -&gt; admin_model -&gt; validate(); if ($query)// if the user's credentials validated... { $data = array('user_name' =&gt; $this -&gt; input -&gt; post('user_name'), 'is_logged_in' =&gt; true); $this -&gt; session -&gt; set_userdata($data); redirect('admin/home/admin_home'); } else// incorrect username or password { $this -&gt; index(); } } function log_out() { $this-&gt;session-&gt;sess_destroy(); redirect('/admin/admin','refresh'); } } </code></pre> <p>The second controller is the home controller:</p> <pre><code>&lt;?php class Home extends CI_Controller { function __construct() { parent:: __construct(); $this-&gt;is_logged_in(); } function is_logged_in() { $is_logged_in = $this -&gt; session -&gt; userdata('is_logged_in'); if (!isset($is_logged_in) || $is_logged_in != true) { $this -&gt; load -&gt; view('admin/forbidden'); } } function admin_home() { $data['main_content'] = 'home_view'; $this-&gt;load-&gt;view('admin/home_view'); } } </code></pre> <p>The model is admin_model:</p> <pre><code>&lt;?php class Admin_model extends CI_Model { function __construct() { parent:: __construct(); } function validate() { $this-&gt;db-&gt;where('user_name',$this-&gt;input-&gt;post('user_name')); $this-&gt;db-&gt;where('password', $this-&gt;input-&gt;post('password')); $query = $this-&gt;db-&gt;get('user'); if($query-&gt;num_rows==1) { return true; } } } </code></pre> <p>Now, it supposed the user to logout and destroy the session, but if I click the back button of my browser I can get page back which was supposed not to be and the session is not destroyed. please tell me what I am doing wrong here. I am using codeigniter 2.1.0.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload