CodeIgniter Forums
Can not set or fetch cookie - 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: Can not set or fetch cookie (/showthread.php?tid=16050)



Can not set or fetch cookie - El Forum - 02-23-2009

[eluser]freshface[/eluser]
The code:

Code:
function switcher($id)
    {
       $this->load->helper('cookie');
       // set the cookie
       $cookie = array(
                          'name'   => 'lang_id',
                          'value'  => $id
                      );
      
       set_cookie($cookie);
        
        var_dump(get_cookie("lang_id"));
        
    //    redirect();
    }


Any ideas?

ps: I work local.


Can not set or fetch cookie - El Forum - 02-23-2009

[eluser]TheFuzzy0ne[/eluser]
That's not the right function for what you're trying to do. You should be using the [url="http://ellislab.com/codeigniter/user-guide/libraries/sessions.html"]sessions[/url] library for that.
Code:
$this->session->set_userdata('lang_id', $id); // Sets the data

$lang_id = $this->session->userdata('lang_id'); // Gets the data
Hope this helps!