The problem is that you misunderstand how the CI get / set cookie (*) works:
when you set a cookie (using $this->input->set_cookie() or an equivalent helper function), you pass an array to it, but internally this array is used to assign the properties that create the cookie. You do not just serialize the array into a file , you create a cookie with a name, set an expiration and provide some content.
The moment you extract a cookie by passing its name, return only its contents , because this is the actual, real content of the cookie. Again, this is not a serialized array.
So, to your code:
$this->load->helper('cookie'); $this->input->cookie('venue_details', TRUE);
Here is your mistake: $cookie2 NOT an array, but STRING : the contents of the cookie. If you var_dump($cookie2) , you will get:
string(5) "Hello"
The problem of the "random value" that you are facing is most likely due to the fact that when you try to access the index "value", php prints the index (string) to an integer (0) and extracts the 0 index of the string. In the case of βHelloβ, you will receive βHβ - plus a nice warning if you have the correct error lever to display it. See for yourself.
(*) If you are interested, here is how to access the cookie (in system / core / Input.php):
function cookie($index = '', $xss_clean = FALSE) { return $this->_fetch_from_array($_COOKIE, $index, $xss_clean); }
And this is how it is retrieved:
function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE) { if ( ! isset($array[$index])) { return FALSE; } if ($xss_clean === TRUE) { return $this->security->xss_clean($array[$index]); } return $array[$index]; }
And how to create:
function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE) { if (is_array($name)) { // always leave 'name' in last place, as the loop will break otherwise, due to $$item foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'name') as $item) { if (isset($name[$item])) { $$item = $name[$item]; } } } if ($prefix == '' AND config_item('cookie_prefix') != '') { $prefix = config_item('cookie_prefix'); } if ($domain == '' AND config_item('cookie_domain') != '') { $domain = config_item('cookie_domain'); } if ($path == '/' AND config_item('cookie_path') != '/') { $path = config_item('cookie_path'); } if ($secure == FALSE AND config_item('cookie_secure') != FALSE) { $secure = config_item('cookie_secure'); } if ( ! is_numeric($expire)) { $expire = time() - 86500; } else { $expire = ($expire > 0) ? time() + $expire : 0; } setcookie($prefix.$name, $value, $expire, $path, $domain, $secure); }