CodeIgniter Forums

Full Version: cookie issue, can you help me?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
sorry for my english, i have an unknow issue on my website:

i try to save a cart in a cookie:

var_dump of the cookie before saving :

array (size=3)
'name' => string 'cart'
'value' => string '[{"id":"13991","id_prod":"18176","qty":1,"gravure":"","options_infos":[],"cadeau":0},{"id":"13983","id_prod":"18168","qty":1,"gravure":"","options_infos":[],"cadeau":0},{"id":"13987","id_prod":"18172","qty":1,"gravure":"","options_infos":[],"cadeau":0},{"id":"279543","id_prod":"29990","qty":1,"gravure":"","options_infos":[],"cadeau":0},{"id":"279554","id_prod":"30001","qty":1,"gravure":"","options_infos":[],"cadeau":0},{"id":"279539","id_prod":"29986","qty":1,"grav ure":"","options_infos":[],"cadeau":0},{"id'... (length=3301)
'expire' => int 2592000

this php function is triggerered on my page to update the cookie cart,
this is what is blocking when i have more than approx  20 items on my cart

PHP Code:
public function refreshCookie() {
$items = array();
if (
parent::contents()) {
foreach (
parent::contents() as $key => $value) {

$prod = new stdClass();

$prod->id $value['id'];
$prod->id_prod $value['id_prod'];
$prod->qty $value['qty'];

if (isset(
$prod->gravure $value['gravure'];

if (isset(
$prod->options_infos $value['options_infos'];
$prod->cadeau $value['cadeau'];
$items[] = $prod;

$cookie = array(
'name' => 'cart',
'value' => json_encode($items),
'expire' => $this->CI->config->item('cookie_panier_lifetime')

this work fine in my local machine but not online when i have more than 20 items
it wotk if i remove the set_cookier line ($this->CI->input->set_cookie($cookie);)
also note that if i use the php setcookie it is the same, so it is not realy a codeigniter issue :/

i don't understand , any help would be appreciated
This may or may not be the issue, but cookies have a limited amount of storage. You need to save an cart_id in your cookie instead and load the content of the cart from cache or from your database.
hello, this cookie is just used to save the cart and load it if the user come back after the session is closed
i don't understand why i have no limiation on my local machine (tested +100 items)
and only 20 on my server
Do you have any other application stored on the domain? The size and amount of cookies are based on domain level.
Non the less, if you solve it at hand, you will have an issues further down the road. So re-design your application before it's too late. :-)
@jreklund is correct you should refactor your code now to save yourself trouble later on down the road.

Save your cart into the database and save a pointer to it in the cookie, then load it from the database.
hello, ok i made a database for data, regards