Login Di Codeigniter

      Hii my name is sance aenul yakin

      Berikut Kode code igniternya
      silahkan dipahami,
      jika tidak mengerti mohon info
      Terimakasih.













Kode Codeigniter untuk Login



Buat database dblogin
tabel->user
fieldnya :
id_user->int->autoincrement->primari key
username->varchar(35)
password->varchar(35)

config.php

$config['base_url'] = 'http://localhost:8080/login/';
$config['encryption_key'] = 's4nc3';

autoload.php

$autoload['libraries'] = array('database','session');
dan setting juga di autoload.php
$autoload['helper'] = array('url');

routes.php
$route['default_controller'] = "welcome";

database.php
Setting databasenya

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'dblogin';
$db['default']['dbdriver'] = 'mysql';

$db['default']['pconnect'] = FALSE //TRUE;

welcome_message.php

<body>

<div id="container">
<h1>Please Login in Here</h1>

<div id="body">
<form action="" method="POST">
<input type="text" name="user" placeholder="Enter Your Username"/>
<input type="password" name="pass" placeholder="Enter Your Password"/>
<input type="submit" name="login" value="Login"/>
</form>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>

</body>

Welcome_message.php
part 2

<body>

<div id="container">
<h1>Please Login in Here</h1>

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

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>

</body>

Controller/Welcome.php

public function index()
{
$this->load->view('welcome_message');
}
public function login()
{
echo "Selamat Datang ";
}

autoload.php

$autoload['model'] = array('login_model');

Welcome.php

public function index()
{
$this->load->view('welcome_message');
}
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);
echo $hasil;
}

login_model

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login_model extends CI_Model {

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

controller/welcome.php

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){
echo 'Login Berhasil ';
}else{
echo 'Gagal Login';
}
}

view/user.php

<!Doctype html>
<html>
<head>
<title>Hal User</title>
</head>
<body>
Selamat Datang Dihalaman user
</body>
</html>

controller/welcome.php

public function index()
{
$this->load->view('welcome_message');
}
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){
redirect('welcome/pageUser');
}else{
echo 'Gagal Login';
}
}
public function pageUser(){
$this->load->view('user');
}


controller/welcome.php

public function index()
{
$this->load->view('welcome_message');
}
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){
redirect('welcome/pageUser');
}else{
$this->session->set_flashdata('err','username dan password Salah');
redirect('welcome/index');
}
}
public function pageUser(){
$this->load->view('user');
}

view/welcome_message.php


<div id="container">
<h1>Please Login in Here</h1>
<?php echo $this->session->flashdata('err')?>
<div id="body">
<form action="<?php echo site_url('welcome/login')?>" method="POST">
<input type="text" name="user" placeholder="Enter Your Username"/>
<input type="password" name="pass" placeholder="Enter Your Password"/>
<input type="submit" name="login" value="Login"/>
</form>
</div>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>

controller/welcome.php

if($hasil>0){
$select =$this->db->get_where('user',array('username'=>$user,'password'=>$pass))->row();  
$data=array('loged_in'=>true,'logerr'=>$select->username);
$this->session->set_userdata($data);
redirect('welcome/pageUser');
}

ket :
get_where('user'
user nama tabel


view/user.php

<!Doctype html>
<html>
<head>
<title>Hal User</title>
</head>
<body>
Selamat Datang <?php echo $this->session->userdata('logerr')?>
</body>
</html>

Controller/welcome.php

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_in'=>true,'loger'=>$select->nama);                  //nama field databasenya
$this->session->set_userdata($data);
redirect('welcome/pageUser');
}else{
$this->session->set_flashdata('err','Pasword salah bro');
redirect('welcome/index');
}
}

controller/welcome.php

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

View/user.php

<body>
Selamat Datang <?php echo $this->session->userdata('logerr')?>
<br><br>
<br><br>
<a href="<?php echo site_url('welcome/logout')?>">Log Out</a>
</body>


ket:

jika eror blank putih

Cara fixnya.
Cek file database.php pada : http://carauntuk.com/system/application/config/
lalu cek pada bagian :
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "xxxx";
$db['default']['password'] = "xxxx";
$db['default']['database'] = "xxxx";
$db['default']['dbdriver'] = "mysqli";
Ubah kata yang diblok menjadi :
$db['default']['dbdriver'] = "mysql";

intinya adalah problem ini terjadi karena aplikasi CI yang kita install menerapkan driver mysqli
yang umumnya pada server shared hosting default aktif adalah driver mysql, hal ini yang membuat
tampilan web jadi blank karena driver atau database mysqli tidak terpangil dengan benar.

Sumber :   http://carauntuk.com/blank-screen-with-code-igniter-ci







Video Download click here

DOWNLOAD


LATIHAN





















Login Di Codeigniter Login Di Codeigniter Reviewed by Leo on 10:08 Rating: 5

No comments