Welcome Guest, Not a member yet? Register   Sign In
how can I use cookie with CodeIgniter
#1

[eluser]Unknown[/eluser]
Hi everyone,

I want to use cookie with CodeIgniter to my login page. I've just find how can I set cookie.

Code:
$cookie = array(
'name'   => 'smth',
'value'  =>  $cookieValue,
'expire' => '0',
'domain' => '.localhost',
'path'   => '/smth',
'prefix' => 'smth_',
'secure' => TRUE
);

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

$cookieValue has md5 characters data. The problem is using cookie, when I use like this
Code:
var_dump($this->input->cookie('smth'));
I've get some boolen false.

How can I use this?

Thanks.



#2

[eluser]DocFunky![/eluser]
Hi,
I got a similar problem and I don't get any cookie or even any information in the VAR_DUMP($COOKIE); as explained above.
So, if I want to use a cookie in localhost (path : www/SocialCart/)what do I hace to do more than :
Code:
$this->load->helper('cookie');
  set_cookie (array(
                   'name'     => 'Session_Cookie_FB',
                   'product_value'  => 'salut',
                   'expire'   => '86500',
                   'domain'   => NULL,
                   'path'     => 'localhost/Session_Cookie_FB/',
               ));
    $cook = get_cookie('Session_Cookie_FB');
  echo'The cookie :<pre>';
  print_r($cook);    
  echo '</pre>';
  echo var_dump($_COOKIE);

Thanks for your Help
#3

[eluser]InsiteFX[/eluser]
your path should be:
Code:
'path' => '/',

If running on a localhost system leave the path set as '/'

Also you can not view a cookie until there is a page refresh so your
code will never work!

Do a redirect:
Code:
redirect('this_controller', 'refresh');

$cook = get_cookie('Session_Cookie_FB');

echo'The cookie :<pre>';
print_r($cook);    
echo '</pre>';
echo var_dump($_COOKIE);

Now you should be able to view the cookie if it is set right.




Theme © iAndrew 2016 - Forum software by © MyBB