If you read the Codeigniter Class Reference setuserdata expects the second argument to be a value, that in case first argument is a key, hence the error.
with the Codeigniter way, you won't be able to achieve what you want as it uses:
on the other hand using vanilla php $_SESSION you can achieve it like so:
this is due to your ENVIRONMENT setting, as you have error_reporting limited at the production (live) server. This is set in your root index.php.
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
Actually $this->session->set_userdata('name', $name); works, but the function userdata() only accepts one argument and expects it to be a string
* Userdata (fetch)
* Legacy CI_Session compatibility method
* @param string $key Session data key
* @return mixed Session data value or NULL if not found
public function userdata($key = NULL)
return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL;
$userdata = array();
$_exclude = array_merge(
foreach (array_keys($_SESSION) as $key)
if ( ! in_array($key, $_exclude, TRUE))
$userdata[$key] = $_SESSION[$key];
No, I already tried this. And set_userdata can have the first parameter as name. I was using it with success.
@ShanilSoni please see my updated answer, if you use php $_SESSION you can resolve your problem. No error on live server is definitely your Environment setting, I've just checked it.
No, I tried everything what all suggested but nothing was working. Finally, I found the issue, CI 3.1.6 was not supporting PHP 7.1, when I moved back to 5.6, it started saving the session. Thank you so much for your help.
I'm clueless then why it was not working in my local environment. I have been facing this issue for 15 days now. When I switched back, it started working somwhow.