I am using CakePHP 3.0, and uploaded it to the server, it was working fine in local but somehow after uploading it to server it shows error
Notice (8): Undefined variable: _SESSION [CORE/src/Network/Session.php, line 438]
If any have idea about that please help me. I am still trying to solve it.
I have also tried to put session_start();
in AppController
and many other places but then it goes blank.
I have found the issue, Its when I was uploading the files to servers it was automatically appending the white blank lines at the end of the AppController and also another controller files.
So when I removed the blank lines from that files it is working fine again
//To detect the file which have issue or extra space or early header start
//File location : vendor/cakephp/cakephp/src/Network/Session.php
public function write($name, $value = null)
{
if (empty($name)) {
return;
}
if (!$this->started()) {
$this->start();
}
$write = $name;
if (!is_array($name)) {
$write = [$name => $value];
}
//remove the comment from bottom line and run your code it will
//show you the exact file from where you have to remove the blank space
//session_start();
$data = $_SESSION ?: [];
foreach ($write as $key => $val) {
$data = Hash::insert($data, $key, $val);
}
$this->_overwrite($_SESSION, $data);
}
Small issue but took long time to detect it,hope this will help you all.
Place this in your php.ini file on your server
session.save_path = “/var/tmp”
You need make sure to start the session at the top of every PHP file where you want to use the $_SESSION superglobal. Like this:
<?php
session_start();
echo $_SESSION['youritem'];
?>
You forgot the Session HELPER.
Check this link : book.cakephp.org/2.0/en/core-libraries/helpers/session.html