SlideShare a Scribd company logo
Sessions in CodeIgniter 3
config/routes.php
$route['default_controller'] = 'SessionController';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
config/autoload.php
$autoload['libraries'] = array('session');
$autoload['helper'] = array('url','html');
SessionController
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class SessionController extends CI_Controller {
public function index()
{
$this->load->view('main_view');
}
public function view()
{
//print value from the key univ
$session_data = $this->session->userdata('univ');
//print data for the key colors
$session_data = $this->session->userdata('colors');
//echo $session_data;
print_r($this->session->userdata());
//print all session data from the array colors
if($this->session->userdata('colors')){
$data=$this->session->userdata('colors');
foreach ( $data as $key=>$var )
{
print "<br/>$key = = > $var<br/>";
}
}else
echo 'No data in the session';
}
public function set()
{
// $this->load->library('session');
$colors = array(
'color1' => 'red',
'color2' => 'yellow',
'color3' => 'blue'
);
//add a variable to session
$this->session->set_userdata('univ','"Al. I. Cuza"');
//add an array to session
$this->session->set_userdata('colors',$colors);
echo "Data has been added to session";
}
public function delete()
{
//delete all session data
$this->session->sess_destroy();
//delete values for key univ
//$this->session->unset_userdata('univ');
//delete values for key color1
//$this->session->unset_userdata('color1');
echo "Data has been removed from session.";
}
}
views/main_view.php
<a href="<?php echo site_url('SessionController/view') ?>">View
Session data</a><br/><br/>
<a href="<?php echo site_url('SessionController/set') ?>">Set
Session data</a><br/><br/>
<a href="<?php echo site_url('SessionController/delete') ?>">Delete
Session data</a><br/><br/>

More Related Content

PPTX
24. CodeIgniter simple login with sessions
PPTX
22.sessions in laravel
PPTX
17. CodeIgniter login simplu cu sesiuni
PDF
Code igniter parameter passing techniques
PDF
Codeigniter : Custom Routing - Manipulate Uri
DOCX
TICT #13
DOCX
TICT #11
DOCX
24. CodeIgniter simple login with sessions
22.sessions in laravel
17. CodeIgniter login simplu cu sesiuni
Code igniter parameter passing techniques
Codeigniter : Custom Routing - Manipulate Uri
TICT #13
TICT #11

What's hot (19)

PDF
Binary Studio Academy 2016: Laravel Controllers
PPTX
23.simple login with sessions in laravel 5
PDF
Feeds drupal cafe
PPTX
20. CodeIgniter edit images
PPTX
6. hello popescu 2
PDF
PowerCMS X
PDF
Building scalable products with WordPress - WordCamp London 2018
PDF
次世代版 PowerCMS 開発プロジェクトのご紹介
PPTX
14. CodeIgniter adaugarea inregistrarilor
KEY
Keeping It Simple
PDF
Practica csv
DOCX
Latihan form login
PDF
Laravel the right way
PPT
Clever Joomla! Templating Tips and Tricks
TXT
Php redirect code
PPTX
15. CodeIgniter editarea inregistrarilor
PDF
Laravel, the right way - PHPConference 2016
PDF
Sample php notification
Binary Studio Academy 2016: Laravel Controllers
23.simple login with sessions in laravel 5
Feeds drupal cafe
20. CodeIgniter edit images
6. hello popescu 2
PowerCMS X
Building scalable products with WordPress - WordCamp London 2018
次世代版 PowerCMS 開発プロジェクトのご紹介
14. CodeIgniter adaugarea inregistrarilor
Keeping It Simple
Practica csv
Latihan form login
Laravel the right way
Clever Joomla! Templating Tips and Tricks
Php redirect code
15. CodeIgniter editarea inregistrarilor
Laravel, the right way - PHPConference 2016
Sample php notification
Ad

Similar to 23. CodeIgniter sessions (20)

PPTX
21. CodeIgniter search
PPTX
16. CodeIgniter stergerea inregistrarilor
PDF
Codeigniter4の比較と検証
PPTX
Oracle Hardening scripts V1.2_DBA.pptxon kelu
PDF
Lviv 2013 d7 vs d8
PDF
Twitter codeigniter library
PPTX
2.routing in zend framework 3
PDF
ACL in CodeIgniter
PDF
Unit testing after Zend Framework 1.8
PPTX
Unit 3 - for php application Sessions.pptx
PDF
Frameworks da nova Era PHP FuelPHP
PDF
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
PDF
Lviv 2013 d7 vs d8
PPTX
Magento Live Australia 2016: Request Flow
PDF
Mojolicious
PPTX
CakePHP workshop
PDF
関西PHP勉強会 php5.4つまみぐい
ODP
Aura Project for PHP
PDF
I Phone On Rails
PDF
WordPress REST API hacking
21. CodeIgniter search
16. CodeIgniter stergerea inregistrarilor
Codeigniter4の比較と検証
Oracle Hardening scripts V1.2_DBA.pptxon kelu
Lviv 2013 d7 vs d8
Twitter codeigniter library
2.routing in zend framework 3
ACL in CodeIgniter
Unit testing after Zend Framework 1.8
Unit 3 - for php application Sessions.pptx
Frameworks da nova Era PHP FuelPHP
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Lviv 2013 d7 vs d8
Magento Live Australia 2016: Request Flow
Mojolicious
CakePHP workshop
関西PHP勉強会 php5.4つまみぐい
Aura Project for PHP
I Phone On Rails
WordPress REST API hacking
Ad

More from Razvan Raducanu, PhD (20)

PPTX
12. edit record
PPTX
11. delete record
PPTX
10. view one record
PPTX
9. add new record
PPTX
8. vederea inregistrarilor
PPTX
PPTX
5. hello popescu
PPTX
4. forme in zend framework 3
PPTX
3. trimiterea datelor la vederi
PPTX
1. zend framework intro
PPTX
18. images in symfony 4
PPTX
17. delete data
PPTX
16. edit data
PPTX
15. view single data
PPTX
14. add data in symfony4
PPTX
13. view data
PPTX
12.doctrine view data
PPTX
11. move in Symfony 4
PPTX
10. add in Symfony 4
PPTX
9. lower in Symfony 4
12. edit record
11. delete record
10. view one record
9. add new record
8. vederea inregistrarilor
5. hello popescu
4. forme in zend framework 3
3. trimiterea datelor la vederi
1. zend framework intro
18. images in symfony 4
17. delete data
16. edit data
15. view single data
14. add data in symfony4
13. view data
12.doctrine view data
11. move in Symfony 4
10. add in Symfony 4
9. lower in Symfony 4

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
01-Introduction-to-Information-Management.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
master seminar digital applications in india
PDF
Computing-Curriculum for Schools in Ghana
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Institutional Correction lecture only . . .
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Basic Mud Logging Guide for educational purpose
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
O7-L3 Supply Chain Operations - ICLT Program
01-Introduction-to-Information-Management.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
RMMM.pdf make it easy to upload and study
Supply Chain Operations Speaking Notes -ICLT Program
master seminar digital applications in india
Computing-Curriculum for Schools in Ghana
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Anesthesia in Laparoscopic Surgery in India
PPH.pptx obstetrics and gynecology in nursing
Institutional Correction lecture only . . .
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
TR - Agricultural Crops Production NC III.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Module 4: Burden of Disease Tutorial Slides S2 2025
Basic Mud Logging Guide for educational purpose
GDM (1) (1).pptx small presentation for students
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
VCE English Exam - Section C Student Revision Booklet

23. CodeIgniter sessions