codeigniter sess_destroy() not working properly,what m i doing wrong?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 13:36:40
Shabib

after going through all the troubles and searching in various places i have finally found a proper solution to this question.the problem arrived because the browser was showing the cached pages.it was not the session that was creating the problem and it was working properly. here is the solution: in the home controller adding a function to clear the cache and calling it in the constructor function does the trick :) here is the home controller with the solution:

<?php
class Home extends CI_Controller
{
    function __construct()
    {
        parent:: __construct();
        $this->is_logged_in();
        $this->clear_cache();
    }
    function is_logged_in() 
    {

        if (!$this->session->userdata('is_logged_in'))
        {
            redirect('/admin/admin');
        }
    }
    function clear_cache()
    {
        $this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, no-transform, max-age=0, post-check=0, pre-check=0");
        $this->output->set_header("Pragma: no-cache");
    }
    function admin_home()
    {
        $data['main_content'] = 'home_view';
        $this->load->view('admin/home_view');
    }
}

now thanks goes to this link " logout feature in code igniter ",here is where i have found the solution and it works perfectly :)

If you logout then although the session is destroyed, the session userdata remains for the duration of the current CI page build.

As a precautionary measure you should do:

function log_out()
{
    $this->session->sess_destroy();
    // null the session (just in case):
    $this->session->set_userdata(array('user_name' => '', 'is_logged_in' => ''));

    redirect('/admin/admin');
}

See: http://codeigniter.com/forums/viewthread/110993/P130/#662369

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!