Home > OS >  Get Javascript session in PHP (Symfony)
Get Javascript session in PHP (Symfony)

Time:11-30

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?

CodePudding user response:

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.

  • Related