2
0
forked from Wavyzz/dolibarr

Optimize cookie usage for boxes. Only 1 cookie per box, instead of 1

cookie
per
parameter.
This commit is contained in:
Laurent Destailleur
2013-09-21 12:30:44 +02:00
parent b20b82df3d
commit fd564f5c7d
7 changed files with 130 additions and 49 deletions

View File

@@ -165,13 +165,21 @@ require_once 'filefunc.inc.php';
// If there is a POST parameter to tell to save automatically some POST params into a cookies, we do it
if (! empty($_POST["DOL_AUTOSET_COOKIE"]))
{
$tmplist=explode(',',$_POST["DOL_AUTOSET_COOKIE"]);
foreach ($tmplist as $value)
require_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
$tmpautoset=explode(':',$_POST["DOL_AUTOSET_COOKIE"],2);
$tmplist=explode(',',$tmpautoset[1]);
$cookiearrayvalue='';
foreach ($tmplist as $tmpkey)
{
//var_dump('setcookie key='.$value.' value='.$_POST[$value]);
setcookie($value, empty($_POST[$value])?'':$_POST[$value], empty($_POST[$value])?0:(time()+(86400*354)), '/'); // keep cookie 1 year
if (empty($_POST[$value])) unset($_COOKIE[$value]);
$postkey=$tmpautoset[0].'_'.$tmpkey;
//var_dump('tmpkey='.$tmpkey.' postkey='.$postkey.' value='.$_POST[$postkey]);
if (! empty($_POST[$postkey])) $cookiearrayvalue[$tmpkey]=$_POST[$postkey];
}
$cookiename=$tmpautoset[0];
$cookievalue=dol_json_encode($cookiearrayvalue);
//var_dump('setcookie cookiename='.$cookiename.' cookievalue='.$cookievalue);
setcookie($cookiename, empty($cookievalue)?'':$cookievalue, empty($cookievalue)?0:(time()+(86400*354)), '/'); // keep cookie 1 year
if (empty($cookievalue)) unset($_COOKIE[$cookiename]);
}
// Init session. Name of session is specific to Dolibarr instance.