作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用 codeigniter 回显 session 数据以查看个人资料或帮助我通过 session 传递 id 来获取用户个人资料
Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller
{
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->load->database();
$this->load->library('session');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->model('User_Model');
$this->load->helper('url');
$this->load->library('parser');
}
public function index()
{
$this->load->view('login');
}
public function register()
{
$this->load->view('Register');
}
public function Save()
{
$this->form_validation->set_rules('email', 'email', 'required');
if ($this->form_validation->run() == false)
{
echo 'Please enter correct email.';
exit;
}
$this->form_validation->set_rules('password', 'password', 'required');
if ($this->form_validation->run() == false)
{
echo 'Please enter password.';
exit;
}
if ($this->form_validation->run() == true)
{
$email = $this->input->post('email');
$password = md5(trim($this->input->post('password')));
$res = $this->User_Model->Save($email,$password);
exit;
}
}
public function Login()
{
$this->form_validation->set_rules('email', 'email', 'required');
if ($this->form_validation->run() == false)
{
echo 'Please enter correct email.';
exit;
}
$this->form_validation->set_rules('password', 'password', 'required');
if ($this->form_validation->run() == false)
{
echo 'Please enter password.';
exit;
}
if ($this->form_validation->run() == true)
{
$email = $this->input->post('email');
$password = md5(trim($this->input->post('password')));
$res = $this->User_Model->login($email,$password);
echo $res;
exit;
}
}
public function dashboard()
{
$this->load->view('welcome');
}
public function logout()
{
$this->session->sess_destroy();
redirect(base_url().'index.php/User/');
}
}
?>
最佳答案
使用原始 php,您可以使用 $_SESSION
检查 session 数据
在 codeigniter 中,您可以使用 print_r($this->session->all_userdata()); 检查 session 数据
关于php - 如何回显 session 数据以查看配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40071812/
我是一名优秀的程序员,十分优秀!