in Education by
I created a login page with codeigniter,but i get the php message. Message: ini_set(): A session is active. You cannot change the session module's ini settings at this time how to fix this? view (login.php) <!DOCTYPE html> Admin Login <?php echo form_open('Verify_login', ['id'=>'loginForm', 'name'=>'loginForm', 'method'=>'post']) ?> controller (Verify_login.php) <?php defined('BASEPATH') OR exit('No direct script access aloowed'); class Verify_login extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('User'); $this->load->helper('url'); $this->load->helper('security'); $this->load->library('form_validation'); $this->load->library('session'); } public function index() { $this->form_validation->set_rules('username', 'Username', 'trim|required'); $this->form_validation->set_rules('password', 'Password', 'trim|required|callback_check_database'); if ($this->form_validation->run() == FALSE) { // if validation failed load the view $this->load->view('admin/login'); } else{ $this->check_database($username , $password); redirect('dashboard', 'refresh'); } } public function check_database($password) { $username = $this->input->post('username'); //query tha database $result = $this->User->login($username, $password); if ($result) { $sess_array = []; foreach ($result as $row) { $sess_array = [ 'id'=>$row->id, 'username'=>$row->name ]; $this->session->set_userdata('logged_in', $sess_array); } return TRUE; } else{ $this->form_validation->set_message('check_database','invalid username and password'); } } } ?> controller(Admin.php) session_start(); //need to call PHP's session object to access it though it class Admin extends CI_Controller { public $data; public function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->helper('form'); $this->load->helper('url'); $this->load->library('form_validation'); $this->load->helper('security'); //load user model $this->load->model('User'); } public function index() { // $this->load->view('admin/index'); if ($this->session->userdata('logged_in')) { $session_data = $this->session->userdata('logged_in'); $data['username'] = $session_data['name']; $this->load->view('admin/dashboard', $data); } else{ //if no session redirect to login page redirect('admin', 'refresh'); // redirect('login'); } } public function logout() { $this->session->unset_userdata('logged_in'); session_destroy(); redirect('home', 'refresh'); } model (User.php) <?php /** *user login claass which extends MY_Model * */ defined('BASEPATH') OR exit('no direct script allowed'); class User extends CI_Model { protected $table = 'users'; public function __construct() { $this->load->database(); } public function login($username ,$password) { var_dump($username); var_dump($password); $this->db->select(['id', 'name', 'password']); $this->db->from($this->table); // $this->db->where('name', $username); // $this->db->where('password', $password); $this->db->limit(1); $query = $this->db->get(); if ($query->num_rows() == 1) { return $query->result(); } else{ return false; } } } ?> JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You don't need this line in admin.php session_start(); //need to call PHP's session object to access it though it When you load the session library, its constructor does this for you.

Related questions

0 votes
    In Google Analytics session time is 30 minutes andhow to change it to 45 minutes?...
asked Oct 3, 2020 in Technology by JackTerrance
0 votes
    What is the difference between these 2 options under the Project menu drop-down? Normally I just adjusted ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    What is the meaning of the message “You cannot have two plugin executions with the same or missing elements”?...
asked May 4, 2021 in Technology by Editorial Staff
0 votes
    You cannot change the size of a page of a Microsoft word document. true or false Select the correct answer from above options...
asked Dec 28, 2021 in Education by JackTerrance
0 votes
    you cannot change the style of the smart art objects is true or false Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    What does it mean by message blocking is active on iphone?...
asked Aug 6, 2022 in Technology by Editorial Staff
0 votes
    In an _________________ attack, an attacker finds an active session & takes over that session. (a) network ... for-Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Oct 31, 2021 in Education by JackTerrance
0 votes
    This one has been bugging me for a while now. Is there a way I can stop Intellj IDEA from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    ___________ function gives an error message if the desired package cannot be loaded. (a) Dplyr (b) Require (c ... of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    If commands are stored in an external file, say commands.R in the working directory work, they may be executed ... of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a parameters.ini file, such as: [parameters.ini] database_user = user database_version = 20110611142248 I want to ... I do this? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Which of the following is used to change active graphic device? (a) dev.set (b) dev.int (c) ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 29, 2021 in Education by JackTerrance
0 votes
    I got this code from somewhere, a book I think: public class KITSMSReceiver extends BroadcastReceiver { @Override ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
...