dongqishun6409 2016-01-27 02:24
浏览 44

用户登录保持重定向回登录Codeigniter

I'm working with sessions for a login function. However every time I attempt log in it just keeps redirecting to the login screen. Below is the code. There is a function set to say that the login is invalid, that is not sending out an error so I'm not sure that it is a login issue.

ATIS Controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Atis extends CI_Controller 
{
        public $status; 
        public $roles;
function __construct()
    {
        parent::__construct();
    $this->load->model('User_model', 'user_model', TRUE);
    $this->status = $this->config->item('status'); 
    $this->roles = $this->config->item('roles');    
    $this->is_logged_in();
    }

function index(){   
    $this->load->view("atis/inc/header");
    $this->load->view("atis/dashboard");
    $this->load->view("atis/inc/footer");
    }
function is_logged_in()
{
    $is_logged_in = $this->session->userdata('is_logged_in');
    if(!isset($is_logged_in) || is_logged_in !==true)
    {
        redirect('main/login');
    }
}

Main Controller

 public function login()
        {
            $this->form_validation->set_rules('email', 'Email', 'required|valid_email');    
            $this->form_validation->set_rules('password', 'Password', 'required'); 

            if($this->form_validation->run() == FALSE) {
                $this->load->view('inc/site_header');
                $this->load->view("site_nav"); 
                $this->load->view('login');
                $this->load->view('inc/site_footer');
            }else{

                $post = $this->input->post();  
                $clean = $this->security->xss_clean($post);

                $userInfo = $this->user_model->checkLogin($clean);

                if(!$userInfo){
                    $this->session->set_flashdata('flash_message', 'The login was unsucessful');
                    redirect(site_url().'main/login');
                }                
                foreach($userInfo as $key=>$val){
                    $this->session->set_userdata($key, $val);
                    $this->session->set_userdata('is_logged_in');
                }
                redirect(site_url().'atis/');
            }

        }

Check login method

public function checkLogin($post)
    {
        $this->load->library('password');       
        $this->db->select('*');
        $this->db->where('email', $post['email']);
        $query = $this->db->get('users');
        $userInfo = $query->row();

        if(!$this->password->validate_password($post['password'], $userInfo->password)){
            error_log('Unsuccessful login attempt('.$post['email'].')');
            return false; 
        }

        $this->updateLoginTime($userInfo->id);

        unset($userInfo->password);
        return $userInfo; 
    }

Yard Function from ATIS Controller

public function yard()

    {
        $this->load->model('atisyard_model');
        $this->data['yards'] = $this->atisyard_model->getyardname();
        $this->data['trackdatabase'] = $this->atisyard_model->gettrains();
        $this->load->view("atis/inc/header");
        $this->load->view('atis/yard_view', $this->data);
        $this->load->view("atis/inc/footer");
    }
  • 写回答

2条回答 默认 最新

  • dongxidui1227 2016-01-27 02:32
    关注

    You are missing a $ in if(!isset($is_logged_in) || is_logged_in !==true)

    Or if still does not work, try changing

    if(!isset($is_logged_in) || is_logged_in !==true) 
    

    to

    if(!$is_logged_in)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图