简体   繁体   中英

session in codeigniter not working after redirect

I am trying to use session in codeigniter. What I have done:

if ( verifyHashedPassword($this->input->post('teacher_password'),$result['teacher_password']))
                    {
                        $this->session->set_userdata('teacher_email',$this->input->post('teacher_email'));
                        $responseArray['success'] = true;
                    }

I am trying to fetch using:

if ( $this->session->userdata('teacher_email') )
            {
                echo "session is set.";
            }
            else
            {
                echo "session is not set.";
            }

after redirection to this page. I am getting alwasy session is not set. Why it is so?

session and cookie configuration is:

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix'   = Set a cookie name prefix if you need to avoid collisions
| 'cookie_domain'   = Set to .your-domain.com for site-wide cookies
| 'cookie_path'     = Typically will be a forward slash
| 'cookie_secure'   = Cookie will only be set if a secure HTTPS connection exists.
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
| Note: These settings (with the exception of 'cookie_prefix' and
|       'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix']    = '';
$config['cookie_domain']    = '';
$config['cookie_path']      = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']  = FALSE;

Changing localhost to 127.0.0.1 worked. If you know the reason behind the issue, a treat will be there for you.

its my code

//cek login
public function index()
    {
        if ($this->session->userdata('id_jurusan') ==1) {
            $where=array('id_jurusan'=>$this->session->userdata('id_jurusan'));
            $value2 = $this->session->userdata('username');
            $data['riwayat_rule'] = $this->guru_mod->get_data_all2('forward_changing','username',$value2);
            $data['user']=$this->guru_mod->get_where($where,'user')->result();
            $this->load->view('guru/index',$data);
        } else if ($this->session->userdata('id_jurusan') ==2) {
            $where=array('id_jurusan'=>$this->session->userdata('id_jurusan'));
            $data['user']=$this->guru_mod->get_where($where,'user');
            $this->load->view('guru/index',$data);
        }else{
            redirect('login');
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM