SlideShare a Scribd company logo
Simple login with sessions in
CodeIgniter 3
config/routes.php
$route['default_controller'] = 'LoginController';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
LoginController
<?php
defined('BASEPATH') OR exit('No direct script
access allowed');
class LoginController extends CI_Controller {
public function index()
{
$data['title'] ="Login form";
$this->load->view('main_view',$data);
}
public function check()
{
if((($_POST["text1"]=="user1")&&($_POST["pass1"]=="pass1")))
{
$this->session->set_userdata('username',$_POST["text1"]);
return redirect('LoginController/ura');
}
else{
echo "Wrong input!";
exit;
}
}
public function ura()
{
if($this->session->userdata('username')){
$data['uname']=$this->session->userdata('username');
$this->load->view('ura',$data);
}
else{
return redirect('LoginController/index');
}
}
public function logout()
{
$this->session->sess_destroy();
redirect('LoginController/index');
}
}
views/main_view.php
<h1>
<?php echo $title; ?>
</h1>
<?php
echo form_open('LoginController/check');
#text control
$data = ['name' => 'text1',
'id' => 'text1',
'value' => '',
'maxlength' => '100',
'size' => '30',
'placeholder'=>'username',
];
#label
echo form_label('Username ', 'text1');
echo form_input($data);
echo "<br><br>";
#password control
$pass = ['name' => 'pass1',
'id' => 'pass1',
'maxlength' => '100',
'size' => '30',
'placeholder'=>'password',
];
echo form_label('Password ', 'pass1');
echo form_password($pass);
echo "<br><br>";
#submit button
echo form_submit('submit', 'Submit!');
echo form_close();
ura.blade.php
<?php
echo "Welcome ".$uname."!";
echo "<br/><br/>";
?>
<a href="<?php echo site_url('LoginController/logout') ?>">Logout</a><br/><br/>

More Related Content

PPTX
23. CodeIgniter sessions
PPTX
17. CodeIgniter login simplu cu sesiuni
PPTX
23.simple login with sessions in laravel 5
DOCX
PDF
Code igniter parameter passing techniques
PDF
Codeigniter : Custom Routing - Manipulate Uri
PDF
Binary Studio Academy 2016: Laravel Controllers
DOCX
Latihan form login
23. CodeIgniter sessions
17. CodeIgniter login simplu cu sesiuni
23.simple login with sessions in laravel 5
Code igniter parameter passing techniques
Codeigniter : Custom Routing - Manipulate Uri
Binary Studio Academy 2016: Laravel Controllers
Latihan form login

What's hot (19)

DOCX
TICT #13
DOCX
TICT #11
PPTX
Goodbye hook_menu() - Routing and Menus in Drupal 8
PDF
Jinja2 Templates - San Francisco Flask Meetup
ODP
Drupal 8 Routing
PPTX
14. CodeIgniter adaugarea inregistrarilor
PDF
Building scalable products with WordPress - WordCamp London 2018
PDF
SQL so close I can paste it (YAPC::NA::2011 lightning talk)
PPTX
Routing in Drupal 8
PPTX
20. CodeIgniter edit images
PDF
Practica csv
PPTX
16. CodeIgniter stergerea inregistrarilor
PDF
Growing jQuery
PDF
Laravel the right way
PPT
07 Php Mysql Update Delete
PPTX
15. CodeIgniter editarea inregistrarilor
PDF
Laravel, the right way - PHPConference 2016
PPTX
6. hello popescu 2
PDF
Owasp & php
TICT #13
TICT #11
Goodbye hook_menu() - Routing and Menus in Drupal 8
Jinja2 Templates - San Francisco Flask Meetup
Drupal 8 Routing
14. CodeIgniter adaugarea inregistrarilor
Building scalable products with WordPress - WordCamp London 2018
SQL so close I can paste it (YAPC::NA::2011 lightning talk)
Routing in Drupal 8
20. CodeIgniter edit images
Practica csv
16. CodeIgniter stergerea inregistrarilor
Growing jQuery
Laravel the right way
07 Php Mysql Update Delete
15. CodeIgniter editarea inregistrarilor
Laravel, the right way - PHPConference 2016
6. hello popescu 2
Owasp & php
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
2.routing in zend framework 3
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
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
2.routing in zend framework 3
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
Ad

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Presentation on HIE in infants and its manifestations
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
01-Introduction-to-Information-Management.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Institutional Correction lecture only . . .
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
RMMM.pdf make it easy to upload and study
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Presentation on HIE in infants and its manifestations
Final Presentation General Medicine 03-08-2024.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
A systematic review of self-coping strategies used by university students to ...
human mycosis Human fungal infections are called human mycosis..pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
01-Introduction-to-Information-Management.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
2.FourierTransform-ShortQuestionswithAnswers.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Institutional Correction lecture only . . .
Pharmacology of Heart Failure /Pharmacotherapy of CHF

24. CodeIgniter simple login with sessions