I am trying to get the cookie value by its name. This is the first time i am using the cookie in codeigniter .
Here is how i am trying to get the cookie value which i have set, but its show output in my view page as bool(false)
How i am setting cookie into my controller....
$ranum=random_string('alnum', 20);//generates random numbers/strings
$cookie = array(
'name' => 'remember_me_token',
'value' =>$ranum,
'expire' => '1209600', // Two weeks
'domain' => base_url(), //my base url is http://localhost
'path' => '/'
);
set_cookie($cookie);
How i am trying trying to get my cookie value is
<?php echo $this->input->cookie('remember_me_token', TRUE); //giving output like bool(false) ?>
Note: i am using ajax when users click the "submit" button
Please help me how to check if cookie is available with this name, if its available then how to retrieve its value into my view page..
Update: I checked my browser cookies,its looking like this...its seems i have problem in setting cookie. If so then please help me why my cookie is not setting?
The Cookie is not available on the same request/page where you set it. Once you set a cookie it must be sent to browse.
From PHP.NET
Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter.
Update:
Base url should be something like yourdomain.com
. Check the $config['base_url']
in your config.php
file. You can't use $config['base_url']=http://localhost/
, you should set it as http://localhost/yourdomain/
or keep it blank.
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|