disini saya memberi nama database saya adalah "arow" dan nama tabelnya adaah "user" ,dan struktur tabelnya sebagai berikut :
nama tabel adalah user |
- edit file autoload.php yang ada di applications/config/autoload.php
menjadi
$autoload['libraries'] = array('database', 'session','xmlrpc');
$autoload['helper'] = array();
menjadi
$autoload['helper'] = array('url', 'file');
- edit file config.php yang ada di applications/config/config.php
menjadi
$http = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') . '://';
$newurl = str_replace("index.php","", $_SERVER['SCRIPT_NAME']);
$config['base_url'] = "$http" . $_SERVER['SERVER_NAME'] . "" . $newurl;
$config['encryption_key'] = '';
menjadi
$config['encryption_key'] = 'cekmyinfo';
- edit file database.php yang ada di applications/config/database.php
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'mysql';
menjadi
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'arow';
$db['default']['dbdriver'] = 'mysql';
- edit file routes.php yang ada di applications/config/routes.php
menjadi
$route['default_controller'] = "login";
- buat file dengan nama login.php di folder controllers
<?php if(!defined('BASEPATH')) exit('Hacking Attempt : Keluar dari sistem..!!');
class Login extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('m_login');
$this->load->library(array('form_validation','session'));
$this->load->database();
$this->load->helper('url');
}
public function index() {
$session = $this->session->userdata('isLogin');
if($session == FALSE) {
redirect('login/login_form');
} else {
redirect('home');
}
}
public function login_form() {
$this->form_validation->set_rules('email', 'email', 'required|trim|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'required|md5|xss_clean');
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
if($this->form_validation->run()==FALSE) {
$this->load->view('welcome_message');
}else{
$email = $this->input->post('email');
$password = $this->input->post('password');
//$level = $this->input->post('level');
$cek = $this->m_login->ambilPengguna($email, $password, 1/*, $level*/);
if($cek->num_rows() <> 0) {
$this->session->set_userdata('isLogin', TRUE);
$this->session->set_userdata('data_user',$cek->row());
// $this->session->set_userdata('level',$level);
redirect('home');
}else {
echo " <script>
alert('Gagal Login: Cek email , password dan level anda!');
history.go(-1);
</script>";
}
}
}
public function logout() {
$this->session->sess_destroy();
redirect('login/login_form');
}
}
?>
- buat file dengan nama home.php di folder controllers
<?php if(!defined('BASEPATH')) exit('Hacking Attempt. Keluar dari sistem.');
class Home extends CI_Controller {
private $datauser;
public function __construct() {
parent::__construct();
$this->load->library(array('session'));
$this->load->helper('url');
$this->load->model('m_login');
$this->load->database();
$this->datauser = $this->session->userdata('data_user');
}
public function index() {
if($this->session->userdata('isLogin') == FALSE) {
redirect('login/login_form');
} else {
$this->load->model('m_login');
$user = $this->session->userdata('data_user');
$data = array();
$data['pengguna'] = $user;
// $data['level'] = $this->session->userdata('level');
//$data['pengguna'] = $this->m_login->dataPengguna($user);
$this->load->view('welcome_home', $data);
}
}
}
?>
- buat file dengan nama meni1.php di folder controllers
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Menu1 extends CI_Controller {
private $datauser;
public function __construct() {
parent::__construct();
if ($this->session->userdata('isLogin') == false){
redirect('login/login_form');
}
$this->load->helper('url');
$this->datauser = $this->session->userdata('data_user');
}
function index(){
$data['judul'] = "Menu satu";
$data['body'] = "Ini hanya isi menu 1";
$data['pengguna'] = $this->datauser;
$this->load->view('view_menu',$data);
}
}
?>
- buat file dengan nama m_login.php di folder models
<?php if(!defined('BASEPATH')) exit('Hacking Attempt : Keluar dari sistem..!!');
class M_login extends CI_Model {
public function __construct() {
parent::__construct();
}
public function ambilPengguna($email, $password, $status) {
$this->db->select('*');
$this->db->from('user');
$this->db->where('email', $email);
$this->db->where('password', $password);
$this->db->where('status', $status);
$query = $this->db->get();
return $query;
}
public function dataPengguna($email) {
$this->db->select('email');
$this->db->select('nama');
$this->db->where('email', $email);
$query = $this->db->get('user');
return $query->row();
}
}
?>
- buat file dengan nama navbar.php di folder views
<?php if($pengguna->level == "1") { ?>
Administrator
<a href="<?php echo site_url('login/logout');?>">Logout</a>
<a href="<?php echo site_url('menu1');?>">menu1</a>
<?php } else if($pengguna->level == "2") { ?>
author
<a href="<?php echo site_url('login/logout');?>">Logout</a>
<?php } else { ?>
subcribe
<a href="<?php echo site_url('login/logout');?>">Logout</a>
<?php } ?>
- buat file dengan nama welcome_message.php di folder views
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="<?php echo base_url('assets/theme');?>/img/favicon.ico">
<title>Page Login Area</title>
</head>
<body>
<?php echo form_open('login/login_form'); ?>
<?php echo validation_errors(); ?>
<h2>Please Login !</h2>
<label>Email</label>
<input type="text" name="email" value="<?php echo set_value('email');?>">
<?php echo form_error('email');?>
<label>Password</label>
<input type="password" name="password" value="<?php echo set_value('password');?>">
<?php echo form_error('password');?>
<input type="submit" value="Sign In"><br>
</form>
</body>
</html>
- buat file dengan nama welcome_home.php di folder views
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<meta http-equiv="refresh" content="60" />
<link rel="shortcut icon" href="<?php echo base_url('asset/theme'); ?>/img/favicon.ico">
<title>Dashboard multiple login</title>
</head>
<body>
<?php $this->load->view('navbar.php'); ?>
<h1>Selamat Datang</h1>
</body>
</html>
- buat file dengan nama view_menu.php di folder views
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<meta http-equiv="refresh" content="60" />
<link rel="shortcut icon" href="<?php echo base_url('asset/theme'); ?>/img/favicon.ico">
<title>Dashboard multiple login</title>
</head>
<body>
<?php $this->load->view('navbar.php'); ?>
<h1><?php echo $judul; ?></h1>
</body>
</html>
agar lebih mudah untuk di pelajari, disini saya menyertakan file download agar kawan semua bisa lebih memahaminya, Download Disini !
Coba lebih dari 2 gan misal ada 3 mungkin keren gan ?
BalasHapusThanks alot :D
hehe iyah mas, :)
Hapusmakasih sudah berkunjung :)
but wait deh kalau boleh kasih saran, coba agan gunakan syntakhigher buat codenya cause that's more beatifull, wait ini pake wordpress ya ?
BalasHapusmakasih untuk sarannya,,,
Hapusini adalah salah satu artikel yang lupa dikasih syntakhigher :)
untuk artikel yg lain ada yang udah beberapa pakai syntakhigher :)
.
ini blogger (google) gan :)
gan minta tolong minta tutorial dasbor dan halaman user codeIgniter
BalasHapusoke gan, next saya akan buatkan :)
HapusPosting Komentar