I am using a java script plug-ins to upload multiple images. Fro that I have use a server side script with is with the plug-ins. In that php file I have $_SESSION variable to assign a value in session. But when I am trying to access that session in my controller's method. I have store my javascript file and its corresponding php file in webroot. Is there any way to get session from webroot into controller.
In your php file in webroot, where you have session_start();
, try changing it to the following:
session_name('CAKEPHP');
session_start();
First you need to define public variable
public $components = array('Session');
After that you can use
$this->Session->read();
In order to write session variable first you need to do is include session component in your controller like :
public $components = array('Session');
Then write your session variable like:
$this->Session->write('variable name', 'your session value');
To get this session variable write
$this->Session->read('variable name');
To delete that particular session variable write
$this->Session->delete('variable name');
SharkofMirkwood's answer worked for me.
session_name('CAKEPHP');
session_start();
print_r($_SESSION);
After this you can access session variable using cake's method
ie
$this->Session->read('session_name');
In your Controller please allow the Session component, if you want to use the session component throughout your application then include in the App Controller.
Once you have done this you can access any session data by using the following method.
$sessionData = $this->Session->read();
debug($sessionData);
If you want to write to the session the you can use the following line.
$sessionWrite = $this->Session->write('Site.name', 'My Site Name');
The documentation and other functions you can use can be found here. http://book.cakephp.org/3.0/en/development/sessions.html