I am trying to store an array of URL parameters (format "utm_xxxx") as a cookie. I am converting the array into json string and creating the cookie but the cookie is not storing any value. The content of the cookie is "%5B%5D" What is wrong with my code?
<?php
//Drop utm cookies
$utm_params_url = array();
if(isset($_GET) && !empty($_GET)){
foreach($_GET AS $k=>$v){
if(preg_match("/^utm_[a-z0-9]+/i",$k)){
$utm_params_url[$k] = $v;
}
}
}
setcookie('bm_utm_params1', json_encode($utm_params_url), time()+(86400*7), '/');
?>