PHP-会话在CodeIgniter 3中重定向后丢失 [英] php - Session are lost after redirect in CodeIgniter 3
本文介绍了PHP-会话在CodeIgniter 3中重定向后丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在CodeIgniter 3中获得帮助.每次登录并重定向到索引页面时,会话都会丢失.
I would like to have some help in CodeIgniter 3. Every time I login and redirect to the index page, session is lost.
这是我的代码:
控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Secretariat extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('SecretariatModel');
$this->load->model('IndiRegModel');
$this->load->model('RoomModel');
$this->load->model('BuildingModel');
$this->load->model('BilletModel');
$this->load->model('BatchRegModel');
$this->load->library('form_validation');
$this->load->library('session');
}
public function secretariatLogin(){
if ($this->session->isSecretariat){
redirect('secretariat/index', $data);
} else{
$data['title'] = 'PACSA - Philippine Association of Campus Student Adviser';
$this->load->view('include/toppage', $data);
$this->load->view('include/defaultnavbar', $data);
$this->load->view('pacsa/slider');
$this->load->view('secretariat/secretariatLogin', $data);
$this->load->view('include/bottompage');
}
}
public function signin(){
$secretariat = array(
'sec_email' => $this->input->post('sec_email'),
'sec_password' => sha1($this->input->post('sec_password'))
);
$user = $this->SecretariatModel->getSecretariat($secretariat);
//print_r($user->name);die();
if(!$user == null){
$newdata = array(
'sec_id' => $user->sec_id,
'sec_name' => $user->sec_name,
'sec_lastname' => $user->sec_lastname,
'sec_email' => $user->sec_email,
'sec_password' => $user->sec_password,
'sec_status' => $user->sec_status,
'sec_address' => $user->sec_address,
'logged_in' => TRUE,
'isSecretariat' => TRUE
);
$this->session->set_userdata($newdata);
redirect('secretariat/index');
} else {
$data['title'] = 'PACSA - Philippine Association of Campus Student Adviser';
$data['message'] = 'Invalid email or password';
$this->load->view('include/toppage', $data);
$this->load->view('include/defaultnavbar', $data);
$this->load->view('pacsa/slider');
$this->load->view('secretariat/secretariatLogin', $data);
$this->load->view('include/bottompage');
}
}
public function index(){
$data['title'] = 'PACSA - Philippine Association of Campus Student Adviser';
$id = $this->session->sec_id;
var_dump($id);
echo die();
$this->load->view('include/toppage', $data);
$this->load->view('include/secretariatnavbar', $data);
$this->load->view('pacsa/slider');
$this->load->view('secretariat/index', $data);
$this->load->view('include/bottompage');
}
}
因此,在重定向到索引页面之后,我想验证是否涉及会话.我试图回显用户名和用户名,但得到一个空值.
So after redirecting to the index page, I want to verify if there is a session involved. I tried to echo the id and the name of the user but I get a null value.
推荐答案
我刚刚解决了我的问题,原来我有旧版本的Codeigniter 3,我将CI升级到了网站上提供的最新版本.谢谢大家的帮助
i just solved my problem turns out i have old version of codeigniter 3 i upgrade my CI to the latest version available on the website . thank you all for the help
这篇关于PHP-会话在CodeIgniter 3中重定向后丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文