Project Tutorials
Introduction Directory Structure Project Setup Remove index.php using htaccess Change Default Controller CSS Add in Project Create Login Page Design Validation on Login Login with Database Flashdata on Login Display Username after Login Logout Design Dashboard Page List user data form database Insert Data Flash message show if data inserted Delete data from datebase Edit data from datebase Active Inactive user status Show active users detail on home page Image Upload Edit Image View Image on Home PageDisplay Username after Login
In this tutorial, I will teach you, how to create display user name after login. It means when user login is success. then we will show user name on dashboard.
Step 1 : Go to Login model and get the user details after login succes.
eg:
<?php
class Login_model extends CI_Model
{
public function login_data($user, $pass)
{
//here i am fetching data from login table using where condition
$query = $this->db->where(['name'=>$user,'pass'=>$pass])
->get('login');
$login = $query->row();
//return user details
return $login;
}
}
?>
Step 2 : Go to Login Controller. So that you will pass user details on session.
eg :
<?php
class Login extends CI_Controller {
public function index()
{
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('uname','Username','required');
$this->form_validation->set_rules('password','Password','required');
if($this->form_validation->run())
{
$user = $this->input->post('uname');
$pass = $this->input->post('password');
$this->load->model('login_model');
$login = $this->login_model->login_data($user, $pass);
if($login){
//here i am passing user details in session
$data = array();
$data['id'] = $login->id;
$data['name'] = $login->name;
$this->session->set_userdata($data);
return redirect('dashboard');
}
else{
$this->session->set_flashdata('fail_login','Invalid Credentials');
return redirect('login');
}
}
else
{
$this->load->view('login');
}
}
}
?>
Step 3 : Go to Dashboard controller and load dashboard view page.
<?php
class Dashboard extends CI_Controller {
public function index()
{
$this->load->view('dashboard');
}
}
?>
Step4 : Open dashboard view page and show user name after login with the help of session userdata.
<h2> Welcome <?php echo $this->session->userdata('name'); ?> </h2>
Result :

Source Code:
Codeigniter tutorial for beginners
In this project. We are providing you, how to create small project in Codeign....
Source CodeElevenstech Web Tutorials
Elevenstech Web Tutorials helps you learn coding skills and enhance your skills you want.
As part of Elevenstech's Blog, Elevenstech Web Tutorials contributes to our mission of “helping people learn coding online”.
Read More
Newsletter
Subscribe to get the latest updates from Elevenstech Web Tutorials and stay up to date