Welcome Guest, Not a member yet? Register   Sign In
Sessions CI 1.7
#1

[eluser]cojogrizli[/eluser]
How can I store cookies after close the browser.

I've set $config['sess_expiration'] = 0; but is not working.

I'm not using sessions database. I've just only need to store the info on the disk and use it the next time when I open the browser.

This is the code that I'm using:
Code:
function addCookieVisit($id)
    {
        if(get_cookie('comemorati_favoriti')){
            $comemorati = explode(',', get_cookie('comemorati_favoriti'));
            if(count($comemorati) == 5){
                array_shift($comemorati);
            }
            if(!in_array($id, $comemorati)){
                array_push($comemorati, $id);
            }
            $total = count($comemorati);
            $i = 1;
            $newCookie = '';
            foreach($comemorati as $sValue){
                if($i == $total){
                    $newCookie .= $sValue;
                }
                else{
                    $newCookie .= $sValue.',';    
                }
                $i++;
            }
            $cookie = array(
                'name'   => 'comemorati_favoriti',
                'value'  => $newCookie,
                'expire' => 0,
                'domain' => '',
                'path'   => '/',
                'prefix' => '',
            );
            set_cookie($cookie);
        }
        else{
            $cookie = array(
                'name'   => 'comemorati_favoriti',
                'value'  => $id,
                'expire' => 0,
                'domain' => '',
                'path'   => '/',
                'prefix' => '',
            );
            set_cookie($cookie);
        }
    }
to store the last fifth different id's in the cookie "comemorati_favoriti".
#2

[eluser]WanWizard[/eluser]
This has nothing to do with sessions, you're just manually creating cookies. For which you set an 'expire' value of zero, which means 'valid till end of browser session'.
#3

[eluser]cojogrizli[/eluser]
I've tried only with the sessions data but even that info was deleted.

Which is the option to keep alive the cookies when reopen the browser?
#4

[eluser]WanWizard[/eluser]
You have to set a proper expiration time: http://php.net/manual/en/function.setcookie.php

For session cookies, if you set the expiration in the config to zero, the cookie will have an expiry of 2 years. If cookies disappear after you closed the browser, did you instruct the browser to clean up cookies?

Are they set at all? So if you don't close the browser, and load another page, is the session the correctly loaded? Which browser are we talking about. Especially IE is very sensitive to proper information, like domain and path.

Assuming you have set your base_url properly, you can do this
Code:
$base_url_parts = parse_url($config['base_url']);
$config['cookie_domain'] = $base_url_parts['host'];
$config['cookie_path'] = $base_url_parts['path'];
unset($base_url_parts);
to automatically define the correct domain and path.




Theme © iAndrew 2016 - Forum software by © MyBB