General |  Social Media |  Miscellaneous
srcraft blog logo
  • Business
  • News
  • Shopping
  • Travel
  • Disease
  • Pets
  • Life
  • Health
  • Technology
  • Category
  • Contact Us
Latest Blog : 
☛ Crystal Resort and Lawns: Premier Hotel Accommodation in Hoshangabad ☛ Insights from My Experience at a Dodge City Meatpacking Plant ☛ Advancements in Sleep Science: Understanding Rest in the Modern Age ☛ New High-Value Cash Back Credit Cards Enter the Market ☛ Exploring the Health Benefits of Coffee ☛ The Impact of Climate Change on Wine Country ☛ One Man, One Dog, and a Journey Across the Globe ☛ Major Airliner Accidents and Incidents in India: A Historical Overview ☛ Boeing 787 Dreamliner: Innovation, Efficiency, and the Future of Air Travel ☛ Air India Ahmedabad Crash: Flight AI-171 
Home > Innovation & Technology > Codeigniter

Session destroy automatically after redirect in codeigniter


Admin panel is not working in Codeigniter. Session is working in codeigniter's controller but session is not working on transfer to other controller.

Because of this the admin panel is also not working and the product is not being added to the cart even on the website.

 

Here is the config code:

 

$config['sess_cookie_name'] = 'ci_session';

 

$config['sess_expiration'] = 7200;

 

$config['sess_expire_on_close'] = TRUE;

 

$config['sess_encrypt_cookie'] = FALSE;

 

$config['sess_use_database'] = TRUE;

 

$config['sess_table_name'] = 'ci_sessions';

 

$config['sess_match_ip'] = FALSE;

 

$config['sess_match_useragent'] = FALSE;

 

$config['sess_time_to_update'] = 3600;

 

Here is the autoload code:

 

$autoload['libraries'] = array('database', 'session');

 

Here is controller code Home.php :

 

class Home extends CI_Controller {

 

 public function __construct() {

        parent::__construct();

        $this->load->library('form_validation');

        $this->load->library('session');

$this->load->model('user','',TRUE);

}

 

public function index() {

 $sess_array = array(

'id' => $row->id,

'login_name' => $row->login_name,

'user_name' => $row->user_name,

'department' => $row->department

);

$this->session->set_userdata('is_admin_login', $sess_array);

 

    }

 

Here is another controller Dashboard.php :

 public function index() {

$userid = $this->session->userdata['is_admin_login']['login_name'];

}

 

This problem sometimes comes because of the session. The solution to this problem is as follows -

 

Solution-1 :

You can use the all_userdata() method for retrieving all session data as an ASSOC array.

 

You can write that in your Home.php controller and you can send the returned value to the view.

 

$data['is_admin_login'] = $this->session->all_userdata();

$this->load->view('your/view.php', $data);

 

Solution-2 :

 

You can load the session library in the constructor of Dashboard.php

 

Example:

 

class Dashboard extends CI_Controller

{

  public function __construct()

  {

    parent::__construct();

    $this->load->library('session');

  }

 

  // Rest of all controller's code here

}

 

Solution-3 :

 

In CodeIgniter 3.x if you just upgraded to PHP version 7.x,

 

go to system/libraries/Session/session.php at line 281 and replace :

 

If you just upgraded PHP version than you have to change some code in CodeIgniter 3.x

 

For this go to system/libraries/Session/session.php

 

and find below code ini_set('session.name', $params['cookie_name']);

 

and replace it with this code ini_set('session.id', $params['cookie_name']);

 

Solution-4 :

Also in Session.php find below code

 

if (isset($_COOKIE[$this->_config['cookies_name']])

        && (

            !is_string($_COOKIE[$this->_config['cookies_name']])

            OR !preg_match('/^[0-9a-f]{40}$/', $_COOKIE[$this->_config['cookies_name']]))

){

    unset($_COOKIE[$this->_config['cookies_name']]);

}

 

Replace OR !preg_match('/^[0-9a-f]{40}$/', $_COOKIE[$this->_config['cookie_name']])

To  OR !preg_match('/^[0-9a-f]{32}$/', $_COOKIE[$this->_config['cookie_name']])

 

Written By: Charles Miller Published in Codeigniter


Search

Publish your passions on srcraftblog.com

Latest Post

☛ Crystal Resort and Lawns: Premier Hotel Accommodation in Hoshangabad

☛ Insights from My Experience at a Dodge City Meatpacking Plant

☛ Advancements in Sleep Science: Understanding Rest in the Modern Age

☛ New High-Value Cash Back Credit Cards Enter the Market

☛ Exploring the Health Benefits of Coffee

☛ The Impact of Climate Change on Wine Country

☛ One Man, One Dog, and a Journey Across the Globe

☛ Major Airliner Accidents and Incidents in India: A Historical Overview

☛ Boeing 787 Dreamliner: Innovation, Efficiency, and the Future of Air Travel

☛ Air India Ahmedabad Crash: Flight AI-171


We are accepting well-written informative Guest Posts on srcraftblog.com

Innovation & Technology

Artificial Intelligent blogs
Cryptocurrency blogs
Digital India blogs
Data science blogs
Neuroscience blogs
Programming blogs

Physical science

Physics blogs
Chemistry blogs
Earth science blogs
Geology blogs
Oceanography blogs
Meteorology blogs

Industry

Business blogs
Economy blogs
Freelancing blogs
Leadership blogs
Productivity blogs
Work blogs

Society

Basic income blogs
Education blogs
Environment blogs
Media blogs
Philosophy blogs
Women blogs
About us |  Write for us |  Terms and conditions |  Privacy Policy |  Our Services |  Contact us

© 2025 SRCRAFT INIDA