0
我在codeigniter中遇到了会话问题。无法在codeigniter中的第二个函数中获取会话内容
我已经使用会话库。所以我在会话中存储了username
。在Login
函数中,我能够存储和检索会话数据。但在第二个函数中,该函数中的GetUserName
我无法从会话中检索userName
。
有没有人有任何想法我在做什么错在这里?
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
header('Access-Control-Allow-Origin: *');
class LoginController extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('session');
}
public function index() {
//$this->load->view('welcome_message');
$this->load->view('login');
}
public function Login() {
$UserName=$this->input->post('UserName');
$Password=$this->input->post('Password');
$this->session->set_userdata('UserName',$UserName);
echo $Name=$this->session->userdata('UserName');
}
public function Log() {
$this->load->view('welcome_message');
}
public function GetUserName() {
echo $U_Name=$this->session->userdata('UserName');
}
}
亚我试过上面的代码,但仍然得到错误为“未定义的索引:用户名”。 – kiran
检查变量'$ userName'是否有任何值 –
是我们需要任何加密密钥的会话.. ?? ?? – kiran