SHOW:
|
|
- or go back to the newest paste.
| 1 | - | <?php |
| 1 | + | <?php /*======GENERATE BY Gunawan=========*/ |
| 2 | - | defined('BASEPATH') OR exit('No direct script access allowed');
|
| 2 | + | |
| 3 | class Demo extends CI_Controller {
| |
| 4 | - | class Admin_login {
|
| 4 | + | |
| 5 | // Login | |
| 6 | - | // SET SUPER GLOBAL |
| 6 | + | public function index($username, $password) {
|
| 7 | - | var $CI = NULL; |
| 7 | + | |
| 8 | - | public function __construct() {
|
| 8 | + | |
| 9 | - | $CI =& get_instance(); |
| 9 | + | $CI->session->set_userdata('username', 'demo');
|
| 10 | - | $CI->load->library('session');
|
| 10 | + | $CI->session->set_userdata('name','ini demo');
|
| 11 | $CI->session->set_userdata('id_login', uniqid(rand()));
| |
| 12 | $CI->session->set_userdata('id','99999');
| |
| 13 | ||
| 14 | - | public function login($username, $password) {
|
| 14 | + | $url = site_url('Demo/dashboard');
|
| 15 | echo "<script>window.location.href = '{$url}';</script>";
| |
| 16 | - | // Query untuk pencocokan data |
| 16 | + | |
| 17 | - | $query = $CI->db->get_where('admins', array(
|
| 17 | + | |
| 18 | - | 'username' => $username, |
| 18 | + | |
| 19 | - | 'password' => sha1($password) |
| 19 | + | |
| 20 | - | )); |
| 20 | + | public function dashboard {
|
| 21 | - | |
| 21 | + | |
| 22 | - | // Jika ada hasilnya |
| 22 | + | echo "coba:";var_dump( $CI->session->userdata('username'));
|
| 23 | - | if($query->num_rows() == 1) {
|
| 23 | + | |
| 24 | - | $row = $query; //$this->CI->db->query('SELECT * FROM admins WHERE username = "'.$username.'"');
|
| 24 | + | |
| 25 | - | $user = $row->row(); |
| 25 | + | |
| 26 | - | $id = $user->admin_id; |
| 26 | + | |
| 27 | - | $name = $user->username; |
| 27 | + | |
| 28 | - | |
| 28 | + | |
| 29 | - | $CI->session->set_userdata('username', $username);
|
| 29 | + | |
| 30 | - | $CI->session->set_userdata('name', $name);
|
| 30 | + | |
| 31 | ||
| 32 | - | $CI->session->set_userdata('id', $id);
|
| 32 | + |