Latihan Pembuatan Login

by sance aenul yakin

1.Buatlah Form ?

<form action="<?php echo site_url('welcome/login')?>" method="POST">
<input type="text" name="user" placeholder="Enter Your Name"/>
<input type="password" name="pass" placeholder="Enter Your Password"/>
<input type="submit" name="login" value="Login">
</form>


2.Buatlah Controller welcome ??


public function login(){
$user=$this->input->post('user',true);
$pass=$this->input->post('pass',true);
$cek=$this->login_model->prosesLogin($user,$pass);
$hasil=count($cek);
if($hasil>0){
$select =$this->db->get_where('tbusers',array('nama'=>$user,'password'=>$pass))->row();
$data=array('loged'=>true,'loger'=>$select->nama);
$this->session->set_userdata($data);
redirect('welcome/pageUser');
}else{
$this->session->set_flashdata('eror191','Try again');
redirect('welcome/index');

}

}

3.buatloah load fiew dengan function page user dan reditect degang function logout?

public function pageUser(){
$this->load->view('user');
}
public function logout(){
redirect('welcome/index');
}

4.Buat lah link url ?

<a href="<?php echo site_url('welcome/logout')?>">

5.Buatlah menampilkan eror

$this->session->set_flashdata('eror191','Try again');
dan
<?php echo $this->session->flashdata('eror191')?>

6.buatlah pemanggilan nama ?
$select =$this->db->get_where('tbusers',array('nama'=>$user,'password'=>$pass))->row();
$data=array('loged'=>true,'loger'=>$select->nama);
$this->session->set_userdata($data);

dan juga tulis.

<h1>Selamat Datang <?php echo $this->session->userdata('loger')?></h1>

7.Buatlah Model deng nama login_model.php

public function prosesLogin($user,$pass){
$this->db->where('nama',$user);
$this->db->where('password',$pass);
return $this->db->get('tbusers')->row();
}





Latihan Pembuatan Login Latihan Pembuatan Login Reviewed by Leo on 18:32 Rating: 5

No comments