akarsingkongAvatar border
TS
akarsingkong
Para sesepuh Codeigniter, Mohon pencerahannya



ane idah googling tapi kaga ketemu gan errornya, mohon pencerahannya dari para sesepuh emoticon-Sorry
login.php

<?php

class Login extends CI_Controller {

function __constructor ()
{

parent::CI_Controller();
$this->load->model('Login_model','',TRUE);
}

function index()
{

if ($this->session->userdata('login') == TRUE)
{
redirect('absen');
}
else
{
$this->load->view('login_view');
}
}

function process_login()
{
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('password','Password','required');

if($this->form_validation->run()==TRUE)
{
$username = $this->input->post('username');
$password = $this->input->post('password');

if ($this->Login_model->check_user($username,$password) ==TRUE)
{
$data = array('username' => $username,'login' => TRUE);
$this->session->set_userdata($data);
redirect('absen');
}
else
{
$this->session->set_flashdata('message','Maaf username atau password salah');
redirect('login/index');
}
}
else
{
$this->load->view('login_view');
}

}

function process_logout()
{
$this->session->sess_destroy();
redirect('login','refresh');
}
}
?>


login_model

<?php

class Login_model extends CI_Model {

function __constructor()
{
parent::CI_Model();
}

var $table = 'user';

function check_user($username,$password)
{
$query = $this->db->get_where($this->table,array('username' => $username,'password' =>$password),1 ,0);
if($query->num_rows() > 0)
{
return TRUE;
}
else
{
return FALSE;
}


}
}


?>

login_view

<html>
<head>
<link rel="shortcut icon" href="<?php echo base_url().'images_fav_icon.png'; ?>" />
<style type="text/css">@import url("<?php echo base_url().'css/reset.css';?> ")</style>
<style type="text/css">@import url("<?php echo base_url().'css/login.css';?> ")</style>
<title>Login</title>
</head>

<body>
<div id="login_box">

<h1>Login Absensi</h1>

<?php
$attributes = array('name'=>'login_form','id'=>'login_form');
echo form_open('login/process_login', $attributes);
?>

<?php
$message = $this->session->flashdata('Message');
echo $message =='' ? '' : '<p id="message">'.$message.'</p>';
?>

<p>
<label for="username">Username :</label>
<input type="text" name="username" size="20" class="form_field" value="<?php echo set_value('username'); ?>" />
</p>

<?php echo form_error('username','<p class="field_error">','</p>');?>

<p>
<label for="password">Password :</label>
<input type="text" name="password" size="20" class="form_field" value="<?php echo set_value('password'); ?>" />
</p>

<?php echo form_error('password','<p class="field_error">','</p>');?>

<p>
<input type="submit" name="submit" id="submit" value="Login" />
</p>
</form>
</div>

</body>

</html>

0
1.1K
3
GuestAvatar border
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Urutan
Terbaru
Terlama
GuestAvatar border
Guest
Tulis komentar menarik atau mention replykgpt untuk ngobrol seru
Komunitas Pilihan