CodeIgniter Forums
[Solved] Codeigniter not setting correct expire time for cookie - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: [Solved] Codeigniter not setting correct expire time for cookie (/thread-67789.html)



[Solved] Codeigniter not setting correct expire time for cookie - wolfgang1983 - 04-09-2017

I am using google chrome. And xampp with windows 10

For some reason the expire time is not set correct for cookie

2017-04-10T11:17:38.801Z its not setting it correct

[Image: 3IWlymI5mwva.png]

I have done this below. I am trying to get it to expire in 12 hours no luck

Question how to make sure it can set the expire time correct.


PHP Code:
$cookie_input = array(
'name' => $this->cookie_name, 
'value' => $data, 
'expire' => '43200', 
'domain' => '.project-ask.com',
'path' => '/', 
'prefix' => 'ci_'
);

$this->CI->input->set_cookie($cookie_input); 


On my config.php session


PHP Code:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 1440;
$config['sess_save_path'] = APPPATH 'cache/session/';
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = TRUE;
 
$config
['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE

This function


PHP Code:
private function write_cookie($data = array()) {
    $data serialize($data);

     if ($this->cookie_encrypt) {
       $this->CI->load->library('encryption');
       $data $this->CI->encryption->encrypt($data);
     }

    $cookie_input = array(
        'name' => $this->cookie_name, 
        
'value' => $data, 
        
'expire' => '43200', 
        
'domain' => '.project-ask.com',
        'path' => '/', 
        
'prefix' => 'ci_'
    );

    return $this->CI->input->set_cookie($cookie_input);
}
  



RE: Codeigniter not setting correct expire time for cookie - wolfgang1983 - 04-09-2017

I have got it working now so far I was using the input->set_cookie(). For me that was causing a bit of issue now using the cookie helper seems to set correct times and other stuff as well.

On my Client.php library

PHP Code:
public function write_cookie($data = array()) {
        $data serialize($data);

        $data $this->CI->encryption->encrypt($data);
      
        $cookie_input 
= array(
        'name' => $this->cookie_name, 
        
'value' => $data, 
        
'expire' =>'86500', 
        
'domain' => '.project-ask.com',
        'path' => '/', 
        
'prefix' => $this->prefix
        
);

        return set_cookie($cookie_input);