Skip to content

Instantly share code, notes, and snippets.

@peerapongsam
Last active February 11, 2016 10:30
Show Gist options
  • Save peerapongsam/8876935ed351a8cef423 to your computer and use it in GitHub Desktop.
Save peerapongsam/8876935ed351a8cef423 to your computer and use it in GitHub Desktop.
CI
<?php
class Login extends CI_Controller
{
public function index()
{
$this->load->helper('form');
$this->load->view('login');
}
}
<?php
class VerifyLogin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('user', '', true);
}
public function index()
{
$this->load->helper('security');
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
if ($this->form_validation->run() == false) {
echo 'Login False';
} else {
echo 'Login Success';
}
}
public function check_database($password)
{
$username = $this->input->post('username');
$result = $this->user->login($username, $password);
if ($result) {
return true;
} else {
return false;
}
}
}
<?php
class User extends CI_Model
{
public function login($username, $password)
{
return true;
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
</head>
<body>
<?=validation_errors(); ?>
<?=form_open('verifylogin')?>
<label for="username">Username:</label>
<input type="text" name="username" id="username" size="20">
<br/>
<label for="password">Password:</label>
<input type="password" name="password" id="password" size="20">
<br>
<input type="submit" name="login" value="Login">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment