Session Management in CodeIgniter with PHP
Today, We want to share with you Session Management in CodeIgniter with PHP.
In this post we will show you Session Management in CodeIgniter with PHP, hear for Session Management in CodeIgniter with PHP we will give you demo and example for implement.
In this post, we will learn about Session Management in CodeIgniter with PHP with an example.
This important post will display you how to start session and destroy all session in (CI)codeigniter.
Sission used to Every all user is associated string with a generate unique session ID created.
The Session Management in Codeigniter is very most important for the (secure) security of web-site.
We need to CI-application check on every function or method is user(authentication) is logged in or not checking.
First of all you need to file : autoload check the session library in CI.
To Simple Start Session in CodeIgniter:
$autoload['libraries'] = array('session');
A Session Class using codeigniter
The Session class all the stores session data information for all each user check as serialized (and all the optionally encrypted data) data in a store the cookie.
The Initializing a Session using codeigniter
$this->load->library('session');
The Retrieving Session Data using codeigniter
$this->session->userdata('item'); $session_id = $this->session->userdata('session_id');
An Adding Custom Session Data using codeigniter
$this->session->set_userdata($array);
Example : session in codeigniter
$sales_newdata = array( 'salesusername' => 'adminng', 'salesemail' => '[email protected]', 'logged_in' => TRUE ); $this->session->set_userdata($sales_newdata);
Retrieving All Session Data using codeigniter
$this->session->all_userdata()
Removing Session Data using codeigniter
$sales_array_items_data = array('salesusername' => '', 'salesemail' => ''); $this->session->unset_userdata($sales_array_items_data);
Flashdata using codeigniter
$this->session->set_flashdata('name', 'computer'); $this->session->flashdata('computer');
Destroying a Session using codeigniter
$this->session->sess_destroy();
Delete Session Data in codeigniter
$this->session->unset_userdata('sales_username');
Example : CodeIgniter-Session Management
//check user login or not if condition if ($this->session->userdata('logged_in')!=FALSE) { // all session data print in codeigniter session print_r($this->session->all_userdata()); }
Example : session in codeigniter
Here you can set all data to session Basic Like.. this in (CI)Codeigniter
$this->load->library('session'); $this->session->set_userdata(array( 'sales_user_id' => $user->sales_uid, 'sales_username' => $user->sales_username, 'sales_groupid' => $user->sales_groupid, 'sales_date' => $user->sales_date_cr, 'sales_serial' => $user->sales_serial, 'sales_rec_id' => $user->sales_rec_id, 'sales_status' => TRUE )); Now you can get one-by-one data get: $sales_u_rec_id = $this->session->userdata('sales_rec_id'); $sales_serial = $this->session->userdata('sales_serial');
How to set session in Codeigniter?
//First of all Start to session $this->load->library('session'); //Try to all session data retriving data: $set_session_id_data = $this->session->userdata('session_id');//set session echo $set_session_id_data;