CodeIgniter Laravel PHP Example Javascript jQuery MORE Videos New

User Login example CodeIgniter framework PHP


In this example we will discuss about User Login example CodeIgniter framework PHP.

We use two file for User Login example CodeIgniter framework.

  1. User.php (CodeIgniter\application\controllers\User.php )
  2. login'.php (CodeIgniter\application\views\login.php)

User.php

<?php
class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->helper('url');
}
public function login()
{
if($this->input->post('login'))
{
$email=$this->input->post('email');
$password=$this->input->post('pass');
$que=$this->db->query("select * from user_login where email='$email' and pass='$password'");
$row = $que->num_rows();
if(count($row)>0)
{
redirect('User/dashboard');
}
else
{
$data['error']="<h3 style='color:red'>Invalid userid or password !</h3>";
}
}
$this->load->view('login',@$data);
}
function dashboard()
{
$this->load->view('dashboard');
}
}
?>

student_registration.php

<!DOCTYPE html>
<html>
<head>
<title>Login form</title>
</head>
<body>
<form method="post">
<table width="600" align="center" border="1" cellspacing="5" cellpadding="5">
<tr>
<td colspan="2"><?php echo @$error; ?></td>
</tr>
<tr>
<td>Enter Your Email </td>
<td><input type="text" name="email"/></td>
</tr>
<tr>
<td width="230">Enter Your Password </td>
<td width="329"><input type="password" name="pass"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="login" value="Login"/></td>
</tr>
</table>
</form>
</body>
</html>

Now run the program on your browser with the below URL:

http://localhost/CodeIgniter/index.php/User/login

http://localhost/CodeIgniter/index.php/User/student_registration