Skip to Content
PHPCODE
CodeIgniter Login Successful
codeigniter code / July 29, 2018

Login Successful in codeingter

step 1:created model loginmodel
step 2: for Example
<?php
class Loginmodel extends CI_Model
{
public function login_valid($username,$password)
{
$q=$this->db->where([‘uname’=>$username,’pword’=>$password])
->get(‘users’);
if($q->num_rows())
{
return $q->row()->id;
//return TRUE;
}
else
{
return FALSE;
}
}
}
?>
step 2:- created dashboard.php in view

<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>
</head>
<body>
<h1>Login Succefull Welcome to login panel</h1>
</body>
</html>

step 3:- created login.php in controller
<?php
class Login extends MY_Controller
{
public function index()
{
$this->load->helper(‘form’);
$this->load->view(‘public/admin_login’);
}
public function admin_login()
{
$this->load->library(‘form_validation’);
$this->form_validation->set_rules(‘username’,’User Name’,’required|trim|alpha’);
$this->form_validation->set_rules(‘password’,’Password’,’required’);
$this->form_validation->set_error_delimiters(“<p class=’text-danger’>”,”</p>”);
if($this->form_validation->run()==TRUE)
{

$username=$this->input->post(‘username’);
$password=$this->input->post(‘password’);
$this->load->model(‘loginmodel’);
$login_id=$this->loginmodel->login_valid($username,$password);
if($login_id)
{
$this->load->library(‘session’);
$this->session->set_userdata(‘user_id’,$login_id);
$this->load->view(‘admin/dashboard’);
//credetials valid login user
}
else
{
echo “password no not match”;
//authentication fail
}
}
else
{
$this->load->view(‘public/admin_login’);
//echo validation_errors();
}
}
}
?>

PHPCODE © 2023