Login and Admin Controller

   
<?php

     /*Login.php controller */

    defined('BASEPATH') OR exit('No direct script access allowed');

    class  Login extends CI_Controller {
        /**
         * Index Page for this controller.
         *
         * Maps to the following URL
         *         http://example.com/index.php/user
         *    - or -
         *         http://example.com/index.php/user/index
         *    - or -
         * Since this controller is set as the default controller in
         * config/routes.php, it's displayed at http://example.com/
         *
         * So any other public methods not prefixed with an underscore will
         * map to /index.php/welcome/<method_name>
         * @see https://codeigniter.com/user_guide/general/urls.html
         */
        public function __construct(){
      
        parent::__construct();
            if(($this->session->userdata('id')!='') || ($this->session->userdata('role')!='') || ($this->session->userdata('name')!='')||($this->session->userdata('IsLogin')===TRUE))
            {
               if($this->session->userdata('role')=='admin'){
                    redirect(site_url('admin'));
               }
            }
            $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
            $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
            $this->output->set_header('Pragma: no-cache');
            $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");  
        }

        /*Function for Login*/
        public function index() {
          
            if(isset($_POST['login'])){
              
                $loginid=$this->input->post('username');
                $password=(md5($this->input->post('password')));
                $where=array('email'=>$loginid,'password'=>$password);
                $field=array('j1c_users.id','j1c_users.role_id','j1c_users.name','j1c_users.email','j1c_users.profile_pic','j1c_role.role');
                $join=array(array('table'=>'j1c_role','condition'=>'j1c_role.id=j1c_users.role_id','jointype'=>'inner'));
                $data['allinfo']=($this->query_model->get_joins('j1c_users',$where,$join,$field,'','',''));
              
                    if(empty($data['allinfo']))
                    {
                       $this->session->set_flashdata('message', 'Please try again. Username or password incorrect.');
                    }
                    else
                    {
                        $session=array(
                        'id'=>$data['allinfo'][0]->id,
                        'name'=>$data['allinfo'][0]->name,
                        'email'=>$data['allinfo'][0]->email,
                        'role'=>$data['allinfo'][0]->role,
                        'profile_pic'=>$data['allinfo'][0]->profile_pic,
                        'IsLogin'=>TRUE,
                    );                        
                        if($data['allinfo'][0]->role=="admin")
                        {
                            $this->session->set_userdata($session);
                            redirect(site_url('admin'));
                          
                        }
                        /*elseif($data['allinfo'][0]['role']=="service_provider")
                        {
                            $this->session->set_userdata($session);
                            redirect(site_url('login'));
                        }*/
                        else{
                            redirect(site_url(''));
                        }
                    }
                  
            }
      
        $this->load->view('login');
        }    
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


<?php

      /* Admin.php controller*/

    defined('BASEPATH') OR exit('No direct script access allowed');

    class Admin extends CI_Controller
    {
        /**
         * Index Page for this controller.
         *
         * Maps to the following URL
         *         http://example.com/index.php/user
         *    - or -
         *         http://example.com/index.php/user/index
         *    - or -
         * Since this controller is set as the default controller in
         * config/routes.php, it's displayed at http://example.com/
         *
         * So any other public methods not prefixed with an underscore will
         * map to /index.php/welcome/<method_name>
         * @see https://codeigniter.com/user_guide/general/urls.html
         */
       
        public function __construct()
        {
           
            parent::__construct();
            if (($this->session->userdata('id') == '') || ($this->session->userdata('role') == '') || ($this->session->userdata('name') == '') || ($this->session->userdata('IsLogin') === FALSE)) {
                redirect(site_url('login'));
            }
            $this->output->set_header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
            $this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
            $this->output->set_header('Pragma: no-cache');
            $this->output->set_header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
        }
       
        /*Function for Logout */
        public function logout()
        {
            $newdata = array(
                'id' => '',
                'name' => '',
                'role' => '',
                'email' => '',
                'profile_pic' => '',
                'IsLogin' => FALSE
            );
            //session destroy
            $this->session->unset_userdata($newdata);
            $this->session->sess_destroy();
            redirect(base_url());
        }
       
        /*Function for Dashboard*/
        public function index()
        {
            //$this->load->view('dashboard');
            redirect(site_url('admin/ticket'));
        }
}





Previous
Next Post »