Codeigniter Sessions not working after migration
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 function userdata()
accepts only one argument and expects it to be a string
if you look into session library (/system/libraries/Session/Session.php), you'll find near row
747:
/**
* 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)
{
if (isset($key))
{
return isset($_SESSION[$key]) ? $_SESSION[$key] : NULL;
}
elseif (empty($_SESSION))
{
return array();
}
$userdata = array();
$_exclude = array_merge(
array('__ci_vars'),
$this->get_flash_keys(),
$this->get_temp_keys()
);
foreach (array_keys($_SESSION) as $key)
{
if ( ! in_array($key, $_exclude, TRUE))
{
$userdata[$key] = $_SESSION[$key];
}
}
return $userdata;
}
but alternatively you can fetch an array like $name=array('firstname'=>'mr smith')
with native $_SESSION like this:
set:
$_SESSION['name']=$name;
or
$this->session->set_userdata('name', $name);
get:
echo $_SESSION['name']['firstname']; //etc..
Codeigniter session stored in database but not working
Actually, it was a problem with Codeigniter 3.1.6 and PHP 7.1.7. I've just upgraded CI to newest version.
codeigniter session not working properly
Some changes needs to be done in config file.
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
This issue is likely to be faced post CI migration.
Make sure model name is declared correctly like
class Name extends CI_Model { }
First letter must be upper case in CI 3. save file in same name.
Another reason is sess_save_path. give correct path that should resolve this error
Codeigniter Session Not Holding Values Across Controllers
I've found a solution to your problem. This issue is common to your CI version.
all you need to do is replace the system folder of your Codeigniter app to a newer system version. and you are all set.
it fix this issue using :
CI_Version: 3.1.2; 3.1.3; 3.1.4
up+
and i'm using the latest version now. 3.1.10.
Codeigniter 3.0.5 Session is not working in online
The issue raised because the difference in php in local and with production server.It could corrected by changing the php version of cpanel matching with local which had initially coded
Related Topics
Compile Error: Cannot Use Isset() on the Result of an Expression
Bad Request. Connecting to Sites via Curl on Host and System
Proper Repository Pattern Design in PHP
How to Get a One-Dimensional Scalar Array as a Doctrine Dql Query Result
Dynamic Paypal Button Generation - Isn't It Very Insecure
How to Enable PHP to Work with Postgresql
Getting Started with PHP Extension-Development
Php: Why Isn't Exec() Returning Output
Reverse Geocoding with Google Map API and PHP to Get Nearest Location Using Lat,Long Coordinates
Colorizing Windows Command Line Output from PHP
(Mysql, PHP) How to Get Auto_Increment Field Value Before Inserting Data
Cannot Send Session Cookie - Headers Already Sent
Rest API Authorization & Authentication (Web + Mobile)
MySQL and PHP - Insert Null Rather Than Empty String
Design Patterns: How to Create Database Object/Connection Only When Needed
Detecting Ajax in PHP and Making Sure Request Was from My Own Website
Replace the Variable Price Range by the Chosen Variation Price in Woocommerce 4+