Welcome Guest, Not a member yet? Register   Sign In
session set userdata, large multi-dimensional arrays
#1

[eluser]bonatoc[/eluser]
Hi,

Just posting this for newbies like me, I thought it might help.

I did not understand why a big multi-dimensional array would not be stored.
I was going crazy, because when doing a
Code:
// GOOGLE MAPS API FULL RESPONSE - BIG ARRAY
$this->session->set_userdata('latest_google_response', $latest_google_response);


// DEBUG ARRAY
echo("<br><b>session->userdata -></b><pre>");
print_r($this->session->userdata);
echo("</font></pre><br>");
exit;

... the big array showed up !
So I assumed the big array was correctly stored into userdata.

But then, when checking on other controller/views, $this->session->userdata was NOT containing 'latest_google_response'.

When you're using ci sessions relying only on cookies, It seems in fact that the 4KB limit is pretty easy to bump into.

Using ci sessions relying on database solved it.
Here's what I use on :
application/config/config.php :

Code:
|--------------------------------------------------------------------------
| Session Variables
|--------------------------------------------------------------------------
|
| 'session_cookie_name' = the name you want for the cookie
| 'encrypt_sess_cookie' = TRUE/FALSE (boolean).  Whether to encrypt the cookie
| 'session_expiration'  = the number of SECONDS you want the session to last.
|  by default sessions last 7200 seconds (two hours).  Set to zero for no expiration.
| 'time_to_update'        = how many seconds between CI refreshing Session Information
|
*/
$config['sess_cookie_name']        = 'ci_session';
// $config['sess_expiration']        = 7200;
$config['sess_expiration']        = 0;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']     = 300;

Hope it helps someone.
#2

[eluser]InsiteFX[/eluser]
The database session will only hold 64kb, you can raise this by
changing the user_data field to either mediumtext or longtext.

InsiteFX
#3

[eluser]smilie[/eluser]
It all says nicely in the user manual:

"Note: Cookies can only hold 4KB of data, so be careful not to exceed the capacity. The encryption process in particular produces a longer data string than the original so keep careful track of how much data you are storing."

Cheers,
Smilie
#4

[eluser]poopants[/eluser]
Hi,

I bumped into the same problem. Your solution did just the trick with my multidimensional
session array.
The only left to do was to add the new table to the db.
Just for convenience, I'll post the sql from the user_guide again. Now everything one needs
to know, is on the same page Smile

Code:
CREATE TABLE IF NOT EXISTS  `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id)
);

thanks everyone !




Theme © iAndrew 2016 - Forum software by © MyBB