Simple MultiLevel Login Codeigniter 2.0.2

Back Again with Codeigniter 2.0.2, nah ne sedikit simple login multilevel di codeigniter.

Controller

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 
Class Login extends CI_Controller
{
	public function __construct(){
		parent::__construct();
		$this->load->helper(array('form','url'));
	}
	public function index(){
		$this->load->view("login");
	}
	public function prosess(){
		if($this->cekuser() == "yes"){
			$data["user"] = $this->input->post('user');
			$data["level"] = $this->input->post('level');
			$newdata = array(
				'username' => $data['user'],
				'level' => $data['level'],
				'status'=>'ok'
			);
			$this->session->set_userdata($newdata);
			//$this->load->view('loginsukses');
			
			if($data["level"] == "admin"){
				$this->load->view('loginadmin');
			}elseif ($data["level"] == "user"){
				$this->load->view('loginuser');
			}elseif($data["level"] == "operator"){
				$this->load->view('loginoperator');
			}else{
				echo "error";
			}
		}else{
			echo "login gagal";
		}
	}
	public function cekuser(){
		$data['user'] = $this->input->post('user');
		$data['pass'] = $this->input->post('pass');
		$data['level'] = $this->input->post('level');
		
		if($data['user']=='yaniar' && $data['pass'] == '123' && $data['level'] == 'admin'){
			return "yes";
		}elseif($data['user']=='ahmad' && $data['pass'] == 'asd' && $data['level'] == 'user'){
			return "yes";
		}elseif ($data['user']=='doni' && $data['pass'] == 'csx' && $data['level'] == 'operator'){
			return "yes";
		}else{
			return "no";
		}
	}
	public function gagallogin(){
		if($this->cekuser()=="no"){
			echo "gagal login";
		}
	}
	public function logout(){
		$this->session->sess_destroy();
		redirect("login/index");
		echo "anda telah berhasil logout";
	}
}

View
login.php

<html>
<head><title></title></head>
<body>
<?php echo form_open("login/prosess"); ?>
<input type="text" name="user">
<input type="password" name="pass">
<input type="text" name="level">
<input type="submit" value="submit"/>
</form>
</body>
</html>

loginadmin.php

<html>
<body>
anda berhasil login <a href="<?php echo site_url(); ?>/login/logout">keluar</a>
</body>
</html>

loginuser.php

<html>
<body>
User  <a href="<?php echo site_url(); ?>/login/logout">keluar</a>
</body>
</html>

loginoperator

<html>
<body>
User  <a href="<?php echo site_url(); ?>/login/logout">keluar</a>
</body>
</html>

hahaha,,begitulah artikel hari ini terima kasih telah membaca..,,:D

6 thoughts on “Simple MultiLevel Login Codeigniter 2.0.2

  1. wah terimakasih ya atas tutorialnya..

    tapi masih ada yg mo saya tanyakan, bagaimana cara agar menghapus (destroy) session di CI. saya menggunakan CI 2. function logout-nya masih meninggalkan session, jika di refresh sessionnya masih ada. mohon penjelasannya, maaf saya masih newbie di CI😀

    salam.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s