Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7082215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:01:09+00:00 2026-05-28T07:01:09+00:00

I cannot seem to get CI’s session library to function the way I want

  • 0

I cannot seem to get CI’s session library to function the way I want it to. Essentially, I am storing 2 different categories of data within the sessions. The data within the 2 categories may contain the same value. Right now my attempt to add a key => value pair to the session is failing, as it is only allowing 1 key => value pair to be associated with the array. It overrides itself each time I do a post.

$arr = array(
    'favorite_products' => array(),
    'viewed_products' => array()
    );


$arr["favorite_products"][] = $fav_id;


$this->session->set_userdata($arr);

This is what the array looks when I print_r it:

Array ( [favorite_products] => Array ( [4f1066c2b7fff] => 1648406 ) [viewed_products] => Array ( ))

Am I doing something wrong, or is this just the way CI’s session library works?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:01:09+00:00Added an answer on May 28, 2026 at 7:01 am

    Make sure you are destroying your session between attempts, but this code should work just fine…

    $arr = array(
        'favorite_products' => array(),
        'viewed_products' => array()
        );
    
    
    $arr["favorite_products"][] = $fav_id;
    $arr["favorite_products"][] = 033333; // another id
    
    
    $this->session->set_userdata($arr);
    

    should give you…

    Array ( 
        [favorite_products] => Array ( 
            [0] => 1648406, 
            [1] => 033333 
        ),
        [viewed_products] => Array ()
    )
    

    If you are trying to do this between requests…

    // if it doesn't already exist in the session, create an empty array.
    if( ! ($favorite_products = $this->session->get_userdata("favorite_products")))
    {
        $favorite_products = array();
    }
    
    $favorite_products[] = "new id or info";
    
    $this->session->set_userdata("favorite_products", $favorite_products);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function, but cannot seem to get it quite right, I have
I cannot seem to get this. Everyone else examples or questions use different functions
I cannot seem to get even vaguely the same data from the Python (Which
Using Spring Security 3.1.0, I cannot seem to get the concurrent session control feature
I have this design which I cannot seem to get right, I would like
I'm terribly new to SQL, and cannot seem to get the desired information out,
This is a very old problem, but I cannot seem to get my head
So obviously I am doing something wrong, but I just cannot seem to get
How can I get jaxb to bind to my Vector? I cannot seem to
I cannot seem to get the following to work directory <- ./ files.15x16 <-

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.