首页 文章

如何回显会话数据以查看配置文件

提问于
浏览
0

如何使用codeigniter回显会话数据以查看配置文件或帮助我通过会话传递id以获取用户配置文件

调节器

<?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/'); 
    }
}   
?>

2 回答

  • 0
    • 使用原始php,使用 $_SESSION 检查会话数据

    • 在codeigniter内,您可以使用 print_r($this->session->all_userdata()); 检查会话数据

  • 0

    Codeigniter遵循MVC设计模型,这意味着数据首先由模块生成然后传递给控制器,最后控制器将数据膨胀到某个视图 .

    从Controller加载视图

    $this->load->view('view_name', $data, true/false);
    

    在这个例子中,您将看到如何加载向其传递一些数据的视图 .

    因此,假设您在视图文件夹中有一个名为 show_session.php 的视图,我们可以在控制器中创建以下方法,以显示您希望用户能够看到的会话数据 .

    public function index()
    {
        $data['info'] = $this->session->all_userdata(); 
        $this->load->view('show_session',$data);
    }
    

    创建视图

    如果您没有该视图,则使用以下内容创建它:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Simple data</title>
    </head>
    <body>
    <?php 
    foreach ($info as $key => $value) {
        echo $key." => ".$value."<br>";
    }
    ?>
    </body>
    </html>
    

    最后将其保存到 /application/views 文件夹中 .

    信用和更多信息:here

相关问题