Welcome Guest, Not a member yet? Register   Sign In
Cookie is not working?
#1
Bug 

This is my login helper:
PHP Code:
<?php 
    
    
function do_login($cname){

        
$ci =& get_instance();

        
$ci->load->helper('cookie');

        
$cookie = array(
            
'name'   => $cname,
            
'value'  => 'thisissomevalue',
            
'expire' => '0',
            
'domain' => '',
            
'path'   => '/',
            
'prefix' => '',
            
'secure' => TRUE
        
);

        
$ci->input->set_cookie($cookie);

    }

?>

No error from the controller but also i cant see any cookie has created? any idea? thanks
Reply
#2

(This post was last modified: 01-06-2015, 04:23 PM by _this.)

Hello rakibtg,

First, maybe you could say "Hello" before asking some help, it seems like nothing but it does count :)

This said, I think you can just do it like that :

PHP Code:
function do_login($cname)
{
 
   $cookie = array(
 
       'name'   => $cname,
 
       'value'  => 'thisissomevalue',
 
       'expire' => '0',
 
       'domain' => '',
 
       'path'   => '/',
 
       'prefix' => '',
 
       'secure' => TRUE
    
);
 
   get_instance()->input->set_cookie($cookie);


You don't need the cookie helper here because you use the input class which is autoloaded by CI, is it working this way ?

P.S. : You should make a validation about $cname, to avoid null, undefined and blank values !
Reply
#3

Thanks for your time! i am not sure, but it still not creating any cookie..
Reply
#4

Have you set your cookie rRelated variables in the config.php?

Reply
#5

(01-07-2015, 01:30 PM)Rufnex Wrote: Have you set your cookie rRelated variables in the config.php?

No, how to do that? Thanks
Reply
#6

A cookie will not show up until the next page refresh.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

In /application/config/config.php you have to search for that lines and fill in your domain.

PHP Code:
$config['cookie_prefix']    = 'yourdomain_';
$config['cookie_domain']    = '.yourdomain.tld';
$config['cookie_path']        = '/';
$config['cookie_secure']    = FALSE;
$config['cookie_httponly']     = FALSE

Reply
#8

(01-08-2015, 05:26 AM)Rufnex Wrote: In /application/config/config.php you have to search for that lines and fill in your domain.


PHP Code:
$config['cookie_prefix'] = 'yourdomain_';
$config['cookie_domain'] = '.yourdomain.tld';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE

Those configs are empty, is it ok?
PHP Code:
$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']        = "/";
$config['cookie_secure']    = FALSE

Thanks
Reply
#9

$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";

Fill there your domain data as you see in my example

Reply
#10

(This post was last modified: 01-13-2015, 03:07 AM by _this.)

@Rufnex :

I never set those config vars and my cookies are working perfectly...

BTW, @rakibtg did it solved it ?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB