Skip to content

Instantly share code, notes, and snippets.

@Rameshwar-ghodke
Created April 1, 2017 05:42
Show Gist options
  • Save Rameshwar-ghodke/7c22a04d716482174c8ebb6eb8588729 to your computer and use it in GitHub Desktop.
Save Rameshwar-ghodke/7c22a04d716482174c8ebb6eb8588729 to your computer and use it in GitHub Desktop.
// first call the following log() function in your controller
eg :-
function log()
{
//$this->load->helper(array('url'));
$this->load->view('login_view');
}
// this function call through the form after submit the login form
eg:
function login_check()
{
$user_name = $this->input->post('user_name');
$user_password = $this->input->post('user_password');
$table = "login";
$where=array('user_name'=>$user_name,'user_password'=>$user_password);
$result = $this->Login->validate($table,$where);
if($result!=0)
{
echo "success";
}
else if($result==0)
{
echo "failed";
}
}
// After that controller call the login_view.php view file in that file normal login form code as--
eg:-
<h2 class="texzt-center"> <strong> Login Form </strong> </h2> <br>
<form name="myform" action="login_check" method="post">
<div class="row">
<div class="form-group col-md-offset-2 col-md-8">
<input type="text" class="form-control" name="user_name" id="uname" placeholder="User Name" style="input-placeholder:color:black;"/>
</div>
</div>
<div class="row">
<div class="form-group col-md-offset-2 col-md-8">
<input type="text" class="form-control" name="user_password" id="password" placeholder="Password"/>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<input type="checkbox" name="remeber" /> <b>Remember Me </b>
</div>
<div class="form-group col-md-6">
<a href="#"><b> Forgot Password </b></a>
</div>
</div>
<div class="row">
<div class="form-group col-md-12">
<button type="submit" class="btn btn-default" > <b>Submit </b></button>
</div>
</div>
</form>
// after submit the button through the action path call the login_check() function which was call in above controller file.
// In Login_check() function check the username and password and run the query and for validate username and passowrd in this function
I call the in login.php file which save in models in that call the validate() function
eg :-
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Model{
function __construct(){
parent::__construct();
}
public function validate($table,$where){
$query = $this->db->get_where($table,$where);
//echo $this->db->last_query(); // echo query on browser
if($query->num_rows()==1){
foreach ($query->result() as $row)
{
$data = array(
'id'=> $row->id,
'user_name'=> $row->user_name,
'user_passwrod'=> $row->user_passwrod,
'logged_in'=>TRUE
);
}
$this->session->set_userdata($data);
//print_r($data);
return $query->result();
}
else
{
return '0';
}
}
}
?>
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment