dongmopu6734 2015-01-18 02:30
浏览 51
已采纳

我如何从codeigniter回显我的会话数组

I know this question has been asked before but my session array is set up different and i would liuke to be able to echo out 'firstname', and 'email' in my members view.

Here is what my session array looks like:

Array
(
    [session_id] => 0be663ae77530e5992d3116af24a216d
    [ip_address] => 
    [user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36
    [last_activity] => 1421547754
    [user_data] => 
    [email] => Array
        (
            [firstname] => Travis
            [email] => theller5567@gmail.com
            [password] => 894027e71b85d60bcc5b0dbe6e83f1f6
        )

    [is_logged_in] => 1
    [firstname] => 
)

I want to get to the email array and echo out the firstname. any help would be greatly appreciated, thank you.

this is my function that sets the userdata. if you see a better way of doing it please by all means share, i would be very greatfull. public function register_user($key){

$this->load->model('model_users');
        if($this->model_users->is_key_valid($key)){
            if($newemail = $this->model_users->add_user($key)){
                $data = array(
                    'firstname' => $this->input->post('firstname'),
                    'email' =>  $newemail,
                    'is_logged_in' => 1
                );
                $this->session->set_userdata($data);
                redirect('login/members');
            }else echo "Failed to add user, please try again.";
        }else echo "invalid Key";
    }
  • 写回答

2条回答 默认 最新

  • dousongqiang2585 2015-01-18 02:35
    关注

    The easiest way I can think to access it would be this:

    $email = $this->session->userdata('email');
    

    Then you can echo the info inside of it with:

    echo $email['firstname'];
    

    and

    echo $email['email'];
    

    From what I can see, CodeIgniter's session library doesn't have any direct ways to access multidimensional array values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?