douzhang3356 2018-11-22 22:53
浏览 99

我在使用会话的codeigniter中遇到了一些问题

I try to check when someone logged in his/her account show the page with the session, I loaded session in libraries but the session doesn't work And Sorry For My Bad English Thanks For The Help :)

This Is The Model

class login_model extends CI_Model
{

function __construct()
{
    parent::__construct();
}

public function check()
{
    $username = $this->input->post('username');
    $password = $this->input->post('password');
    $remember = $this->input->post('remember');

    $this->db->select('username','password');
    $this->db->from('user');
    $this->db->where('username',$username);
    $this->db->where('password',md5($password));

    $result = $this->db->count_all_results();

    if($result > 0)
    {
        $data_session = array(
            'username'=>$username,
            'islogin'=>true,    
        );
        $this->session->set_userdata($data_session);
        redirect('post/index');
    }

This Is The Controller

class Post extends CI_Controller
{
public function index()
{

    $login = $this->session->userdata('islogin');

    if($login == true)
    {
        $data = array (
            'name' => 'Hello',
        );
        $this->load->view('post/index',$data);
    }
    else {
        redirect('login/index');
    }

}
}

This Is The Config

$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'weblogdata';
$config['sess_expiration'] = 3600;
$config['sess_save_path'] = 'tbl_ci_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;

$config['encryption_key'] = m.D~wt,wA:MjS9$]g<H4Z7eW.7`0vDbX$F`LUgCg+>$1?0L$vq1:7vaVf&d{U(   
  • 写回答

2条回答 默认 最新

  • dongsun2789 2018-11-23 02:44
    关注

    set your session condition on contruct(), change the controller to be like this :

    function __construct() {
    parent::__construct();
            if($this->session->userdata('islogin') != true)
            {
                redirect('login/index');
            }
    }
    
    function index() {
            $data = array (
            'name' => 'Hello',
        );
        $this->load->view('post/index',$data);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢