I am using cakePHP 1.26.
In a controller, I got a function which contains these lines of code:
$this->Session->write('testing', $user);
$this->Session->read('testing');
Now the system wrote a session and stored on the server.
Is it possible to use Javascript or Jquery to read the session named ‘testing’ ?
The PHP session is stored in webserver’s memory while JavaScript runs in the webclient (webbrowser). Those are in real world two physically separate and independent machines. They usually can only communicate with each other over network using HTTP protocol.
You have 2 options:
Let PHP print the session data as if it’s a JS variable:
Let JS request it from the server end using Ajax. Here’s a jQuery based example:
with basically this in
script.php:Needless to say that option 1 is the most easy and straightforward.