CodeIgniter Forums
cookie issue, can you help me? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: cookie issue, can you help me? (/showthread.php?tid=75896)



cookie issue, can you help me? - michaelvuillermoz - 03-27-2020

hello
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 :

Code:
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(
$value['gravure'])){
$prod->gravure $value['gravure'];

if (isset(
$value['options_infos'])){
$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->CI->input->set_cookie($cookie);


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
regards


RE: cookie issue, can you help me? - jreklund - 03-27-2020

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.


RE: cookie issue, can you help me? - michaelvuillermoz - 03-28-2020

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


RE: cookie issue, can you help me? - jreklund - 03-28-2020

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. :-)


RE: cookie issue, can you help me? - InsiteFX - 03-28-2020

@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.


RE: cookie issue, can you help me? - michaelvuillermoz - 03-29-2020

hello, ok i made a database for data, regards