Welcome Guest, Not a member yet? Register   Sign In
Retrieving Cookies with CI?
#1

[eluser]WoolyG[/eluser]
Hi all,

I've searched the forums, but cannot find any relevent info on this. I simply would lke to set, and retrieve, cookie data, but it's consistently returning bool(false)after I've supposedly set it.

Here's what I'm doing:

Controller:

Code:
class Args extends Controller {

    function Args()
    {
        parent::Controller();    
        $this->load->model('Header_model');    
        $this->load->model('Home_model');    
        $this->load->model('Argument_model');    
        // Load the cookie Helper
        $this->load->helper('cookie');
    }
.
.
.

        function a(){
        
        .
        .
        .
        .
        
        
        if (!get_cookie('mysite_cookie')) {
            // cookie not set, first visit
        
            // create cookie to avoid hitting this case again
            $cookie = array(
                'name'   => 'mysite_cookie_value',
                'value'  => 'The Cookie Value',
                'expire' => time()+86500,
                'domain' => '.mysite.com',
                'path'   => '/',
                'prefix' => '',
            );
            set_cookie($cookie);
        }
        
        
        .
        .
        . //There's other non-related stuff in this function, for clarity
        . //it's not included
        .        
        

        
        $this->load->view('page_view', $data);        
    }

}


View:
Code:
Cookie: <?php echo get_cookie('mysite_cookie'); ?>

<?php var_dump(get_cookie('mysite_cookie'));  ?>


..the var_dump is returning bool(false) data. Cookies are enabled in the browser. Can anyone point out where the fault is above, and how I call the cookie value?

All help appreciated.

Regards
WoolyG
#2

[eluser]InsiteFX[/eluser]
Did you set the cookie info in application/config.php ?

Also if your running IE you can not use the _ underscore
character it doe's not like it.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB