Home » Php » In PHP 7 session is not working in codeigniter

In PHP 7 session is not working in codeigniter

Posted by: admin October 26, 2017 Leave a comment

Questions:

I am using PHP 7 version my login page is not working. But is working fine in php 5.6 version. I did not get any error showing in code. not set data in user set_userdata.

Here is my Code:

public function login()
{



        $data['error'] ="Invalid Login";
        $this->form_validation->set_rules('email', 'Email', 'trim|required|callback_email_exists|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'trim|required');
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('frontend/auth/login');
            $error = '<div class="alert alert-danger text-center">' . validation_errors() . '</div>';
        }
        else
        {
             $email=$this->input->post('email');
             $password=$this->input->post('password');
             $sql=$this->db->get_where('users',array('email'=>$email,'status'=>1, 'activation'=>1));    


            if ($sql->num_rows() > 0)
            {

                $row = $sql->row();

                echo $password;
                echo $stored_pass = $row->password;     
                echo "<br />";




                if ($this->bcrypt->check_password($password,$stored_pass)) 
                {


                    $now=date("Y-m-d H:i:s");
                    $this->db->where('id',$row->id);
                    $this->db->update('users',array('updated_at'=>$now));
                    $sesdata = array(
                        'userid'  => $row->id,
                        'email'     => $row->email,
                        'username' => $row->username,
                        'role' => $row->type,
                        'access'=>json_decode($row->role,true)
                    );

                    $this->session->set_userdata('user_session',$sesdata);

                    redirect('schedule');   
                }
            }
            else
            {
                $this->session->set_flashdata('msg','Invalid Credential...');
                redirect('oauth/login');
            }
        }
    }

I am using PHP 7 version my login page is not working. But is working fine in php 5.6 version. I did not get any error showing in code. not set data in user set_userdata.

Answers: