CodeIgniter Forums
$this->input->cookie() does not take into account cookie prefix from config.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: $this->input->cookie() does not take into account cookie prefix from config.php (/showthread.php?tid=14840)



$this->input->cookie() does not take into account cookie prefix from config.php - El Forum - 01-16-2009

[eluser]ptrippett[/eluser]
Version 1.7

When a Cookie prefix has been set in the config.php file $this->input->cookie() does not take this into account when retrieving cookie from the Cookie globa array.

Does not work:
Code:
$value = get_cookie('myvar');
if (strlen($value) == 0) {
      $value = 'Some Value';
      set_cookie('myvar', $value, 31556926, '.mydomain.com', '/', '');
}

Works:
Code:
$value = get_cookie('myprefixfromconfig_myvar');
if (strlen($value) == 0) {
      $value = 'Some Value';
      set_cookie('myvar', $value, 31556926, '.mydomain.com', '/', '');
}

Is this by design or a bug?


$this->input->cookie() does not take into account cookie prefix from config.php - El Forum - 01-17-2009

[eluser]bitist[/eluser]
It seems that the prefix is not handled by get_cookie function. Change the function in you cookie_helper.php to
Code:
if (!function_exists('get_cookie')) {
    function get_cookie($index = '', $xss_clean = FALSE, $prefix = '') {
        $CI =& get_instance();
        if($prefix == '' && $CI->config->item('cookie_prefix') != '') {
            $prefix = $CI->config->item('cookie_prefix');
        }
        return $CI->input->cookie($prefix.$index, $xss_clean);
    }
}