I have an application built using CodeIgniter 3.1.6. I was carrying out testing on a subdomain on the production server. I pointed the main domain to the folder and also changed $base_url in config.php to the correct URL. ($cookie_domain within config.php has never been set.)
However, session data is now not working. I have tried some testing, the session data can be set and read within one controller.
$this->session->set_userdata('name', $name);
echo $this->session->userdata('name');
However this doesn't work across URLs. For example:
// controllers/Contact.php
$this->session->set_userdata('name', $name);
// controllers/Welcome.php
echo $this->session->userdata('name');
Any ideas as to why this may not work on a different domain?
There have been several issues reported for incompatibility of PHP version 7.1 and CI 3.1.6 not supporting
$this->session->set_userdata('name', $name);
well,
$this->session->set_userdata('name', $name);
works, but the functionuserdata()
accepts only one argument and expects it to be a stringif you look into session library (/system/libraries/Session/Session.php), you'll find near row
747:
but alternatively you can fetch an array like
$name=array('firstname'=>'mr smith')
with native $_SESSION like this:set:
or
get: