Codeigniter - cookies do not work in internet explorer 8 - codeigniter

This code works in all browsers except Internet Explorer 8
$this->input->set_cookie(array(
'name' => 'test_cookie',
'value' => 'hello from cookie',
'expire' => 360000000,
'secure' => FALSE
));
echo get_cookie('test_cookie');
How to solve this problem? Why does not set_cookie?

I had a similar issue where only IE would refuse to accept a cookie. Turned out the computer's time zone wasn't set correctly (it was 17 hours ahead in the future, set to US PST while the server was in Australia), so what was happening is that the cookie was instantly expiring.

try:
echo $this->input->cookie('test_cookie');

I solved my problem using the function in helper
function setcookie_ex($name, $value, $expire)
{
$cookie_path = '/'; $cookie_domain = ''; $cookie_secure = false;
// Enable sending of a P3P header
header('P3P: CP="CUR ADM"');
if (version_compare(PHP_VERSION, '5.2.0', '>='))
setcookie($name, $value, $expire, $cookie_path, $cookie_domain, $cookie_secure, true);
else
setcookie($name, $value, $expire, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure);
}

Related

Not getting cookie value in codeigniter

Here is my code to set cookie
$cookie = array(
'name' => 'City',
'value' => $city,
'expire' => 86400 * 30,
'domain' => '.localhost',
'path' => '/',
'prefix' => 'picker_',
);
$this->input->set_cookie($cookie)
and i loading cookie helper in constructor of a controller.
my cookie is set form 1 month and i check in browser my cookie is set name
'City' and value = '10'. the problem is when i retrieve the value i get the blank page nothing is printing
here the code of fetching value
echo $this->input->cookie('picker_City');
i also try var_dump
var_dump($this->input->cookie('City', false));
it return false
what is the error.
You have to load the helper cookie first before using set_cookie
$this->load->helper('cookie');
and then use set_cookie
If you are using cookies very often , its better you load it in the autoload.php in the config folder.
in the autoload array
$autoload['helper'] = array('cookie');
Did you load it?
NOTE:
For local testing, leave the domain value blank.
'domain' => '',

How to work with CodeIgniter's cookie helper

This is my first post in stackoverflow and i'm really excited about that.
Actually i have problems with codeigniter cookie helper.
Take look at my codes:
$this->load->helper('cookie');
$cookie = array(
'name' => $nid,
'value' => 'checked'
);
$this->input->set_cookie($cookie);
echo $this->input->cookie();
// print_r($this->input->cookie();
as you see a declared an array called $cookie, then i set the cookie with that. but it seems that i made a mistake in setting cookies, because , the cookie doesn't set !
the immediate calling $this->input->cookie() returns nothing !
Does any one have any suggestion, where do i misunderstand the cookie helper of CI !?
var_dump() $this->input->set_cookie($cookie); // This returns NULL !
You need to give expiration time also in $cookie array and you are not echoing cookie what have you set. try this code
$this->load->helper('cookie');
$cookie = array(
'name' => $nid,
'value' => 'checked',
'expire' => '86500'
);
$this->input->set_cookie($cookie);
echo $this->input->cookie($nid, TRUE);

Ajax dont return values in drupal 7

Im in drupal 7, i need to make a select with many options, depends of the option taken, in a textarea will be loaded several values in a string.
After hours of test i come here for help.
Im working on a basic page:
function ajax_load_all_admins($form, &$form_state) {
$form = array();
$form['changethis'] = array(
'#type' => 'select',
'#options' => array(
'' => '',
'1' => 'Cargar todos los admins'
),
'#ajax' => array(
'event' => 'change',
'callback' => 'ajax_load_all_admins_callback',
'wrapper' => 'listaCorreos-div'
)
);
$form['listaCorreos'] = array(
'#type' => 'textarea',
'#prefix' => '<div id="listaCorreos-div">',
'#suffix' => '</div>'
);
if (!empty($form_state['values']['changethis'])) {
$payments_list = db_query('QUERY WORKING WELL');
$value = '';
foreach ($payments_list as $payment) {
$value .= $payment->admin . ',';
}
trim($value, ',');
$form['listaCorreos']['#default_value'] = $value;
}
return $form;
}
function ajax_load_all_admins_callback($form, $form_state) {
return $form['listaCorreos'];
}
$form = drupal_get_form('ajax_load_all_admins');
print drupal_render($form);
The Ajax call is working but i only recibe:
0: {command:settings, settings:{basePath:/, pathPrefix:,…}, merge:true}
No other one position.
I think it can be for the drupal_render, but dont know why?
Thanks in advice.
since the ajax itself works;
Looks to me like the db_query isn't working well and/or returning unexpected results.
My advice: You should be able to debug. i.e. setting a breakpoint and stepping into your code line by line
I do it with netbeans & XDEBUG
This should gives you a great edge solving this & upcoming similar problems, as you'll be able to monitor your variables & the execution tree of your code
Best of luck.
--edit-- This should be totally in the comment section, but ... new here , cant comment at the moment.. apologies.
I was doing this ajax functions in a simple view, created to make an specific form.
I move all the logic to a new module, instead of simple view and now is working.
I take a look to the ajax examples of "examples module" and test if they works on a simple view,like my code, dont works.
I think for any reason, drupal ajax only works if the render is not manually, like i was doing.
Thanks.

Cookies not beeing set, codeigniter

I'm trying out cookies for first time in CI. Cant get it to work. Here's my code:
class Site extends CI_Controller {
public function index(){
$this->load->view('input_view');
$this->load->helper('cookie');
$this->test();
}
public function test(){
$cookie = array(
'name' => 'Test',
'value' => 'The Value',
'expire' => '86500',
//'domain' => '.some-domain.com',
'path' => '/',
'prefix' => 'myprefix_',
'secure' => TRUE
);
$this->input->set_cookie($cookie);
var_dump(get_cookie('Test'));
}
var_dump... returns false. I understand it does this the first time but should'nt it be true after reloading the page? I can't see any "Test" cookie in my web tools in Chrome either. Do I need the "domain" row? I googled some and if I understood it was optional? If it isn't, what am i suppose to write there? Localhost? In my config file i have this settings for cookies
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "";
$config['cookie_path'] = "/";
$config['cookie_secure'] = FALSE;
I'm guessing you're not running https for development.
The secure flag on your cookie forces the cookie to be sent over HTTPS only;
Secure:
If this cookie can ONLY be sent over HTTPS (SSL), set this value to true.
Set it to false, and the cookie should work.

how to get and use codeigniter cookies?

I am trying to use codeigniter cookies so that i can bookmark some topic , i don't know how to get cookies vale and use it to display bookmarked item in the user browser , it doesn't work when i try to display cokies value using print_r(); please help how to proceed. Thanks
function index(){
$this->load->helper('cookie');
$data['title'] = 'some bookmark';
$cookie = array(
'name' =>'mycookie',
'value' => 'some val',
'expire' => '86500',
'domain' => '.localhost',
'path' => '/',
'prefix' => 'something_'
);
set_cookie($cookie);
$this->load->view('bookmark', $data);
}
Browsers have trouble dealing with localhost (or .localhost) as the domain for cookie storage - they expect a domain to have at least two dots. Try setting the domain to FALSE (or don't set it) while testing.
If that still doesn't work, can you show us how you're retrieving the cookie data?

Resources