正常运行后,首次尝试登录失败

时间:2019-12-19 15:11:01

标签: php codeigniter codeigniter-3

现在我正在localhost上测试我的项目..但是当第一次尝试登录时。它什么也没有显示,意味着页面不重定向('admin / dashboard');。 但是当我下次尝试时..一切正常.. 请任何人都可以帮助! 预先感谢。

I am adding a image here. so that you can see what actual the problem was,

这是模型文件。

<?php 

class Admin_model extends CI_Model{
    public function login($username,$password){
        $enc = md5($password); //for password encryption
        $this->db->where('username',$username);
        $this->db->where('password',$enc);
        $result=$this->db->get('admin');
        if($result->num_rows()==1){
            return $result->row();
        }else{
            return false;
        }
    }
}

这是我的控制器文件。

<?php

class Admin_login extends CI_Controller{

    public function __Construct(){
        parent::__Construct();
        $this->load->model('admin_model','secure_admin_model');  //here i am including model file..  
    }
    public function login(){

        $this->form_validation->set_rules('username','Username','trim|required');
        $this->form_validation->set_rules('password','Password','trim|required');
        if($this->form_validation->run()==FALSE){
            $this->load->view('admin/layouts/admin_login');
            $this->session->unset_userdata('logged_in');
        }
        else{
            $username=$this->input->post('username');
            $password=$this->input->post('password'); // i am using md5 for hashing
            $userid=$this->secure_admin_model->login($username,$password);
            if($userid){
                $user_data=array(
                    'user_id'=>$userid,
                    'username'=>$username,
                    'logged_in'=>true
                );
                $this->session->set_userdata($user_data);
                $this->session->set_flashdata('pass_login','You are logged in'); // Here i am creating session..
                redirect('admin/dashboard');
            }
            else{
                $this->session->set_flashdata('wrong_pass','Wrong Username and password'); // for wrong password
                redirect('admin/login');
            }
        }
    }

0 个答案:

没有答案