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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分