How to get cookies to work?

#1
[eluser]gh0st[/eluser]
I am trying to figure out how to get cookies to work with CI, but they do not appear to work,

I am wanting to store a value for later use.

I am doing a basic example:

Code:
class Test2 extends Controller
{

    function Test2()
    {

        parent::Controller();    
        $this->output->enable_profiler(TRUE);
    }
    
    function index()
    {
        $this->load->helper('cookie');
        
        $cookie = array(
               'name'   => 'testcookie',
               'value'  => 'hello world',
               'expire' => '86500',
               'domain' => '.localhost',
               'prefix' => 'my_'
           );
        
        print set_cookie($cookie);
                        
        redirect("/test2/test_my_cookie");
        exit;
    } // end function
    
    
    function test_my_cookie()
    {
        print __FUNCTION__;
    
        print '<p><pre>';
        print_r($_COOKIE);
        print '</pre></p>';
        
        print get_cookie('my_testcookie');
        
    } // end function

} // end class

The cookie values are always empty. I have tested a PHP cookie (hard-coded) and this works fine, but the CI ones don't -- why not?

How do I get cookies to work?

#2
[eluser]wabu[/eluser]
As a test, try setting domain => false in the code you posted and see if that works.

Check out:

http://us.php.net/manual/en/function.set....php#73107
http://us.php.net/manual/en/function.set....php#71743


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.