-2

I'm trying to get a session variable value set in JS with PHP in back-end (I'm using Symfony).

I set my variable like so:

sessionStorage.setItem('test-name', file);

This works well because I can see in the browser console my session variable and its value. However, on the back-end, I'm unable to get it. I tried the following:

$this->get('session')->get('test-name');

But it doesn't work. What am I doing wrong?

yivi
  • 42,438
  • 18
  • 116
  • 138
ArbreMojo
  • 89
  • 2
  • 8
  • 3
    `sessionStorage` is an browser api and does not interact with server sessions. PHP Sessions are stored on the server side and the client can only reference it with PHPSESSID cookie. – Code Spirit Nov 29 '21 at 14:44

1 Answers1

1

Your JavaScript program and your PHP program are different programs running on (most of the time) different computers.

JavaScript's sessionStorage accesses a store inside the browser.

PHP's sessions access a store on the server.

They are not the same store.


If you want to store the data in a shared location, use the PHP session store. Allow JavaScript access to it by writing a web service and using Ajax to interact with it.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335