When should I use PHP Session vs Browser Local Storage vs JavaScript Object Parameters?

When is it appropriate to use the many different ways that modern AJAX-based applications store data? I hope for some specific recommendations that I can give to the developers. This is what I see so far, and it is getting messy.

PHP server-side session: PHP session data is probably the oldest way to store session-based information. I often pass parameters through various AJAX calls from JavaScript / jQuery objects - for storage in a PHP session. I also return data objects (some session data) back as a response / result to JavaScript / jQuery methods.

Local storage on the basis of the browser: . This is often used to store data that needs to be stored on the front panel, but I'm not sure when to use it. One good option was to save geolocation from navigator.geolocation. I store a lot of information here, but I'm not sure if this is wise. It does not seem to expire, but can be removed from Resources.

JavaScript object with configuration parameters: I created JavaScipts objects using the init method, which sets the 'settings' parameter. This is very useful since I usually build it from data passed from PHP. With jQuery Mobile, this data can be saved even from page to page and changed with responses to an AJAX request.

So, what recommendations would you point out for using each?

+4
1

PHP , . , .

, . , .

, , .

COOKIES ( expired them at session close), IndexedDb ( http://caniuse.com/#feat=indexeddb).

, - , , .

LocalStorage, , , Cookies .

PHP, PHP , ( ).

.

+7

Source: https://habr.com/ru/post/1546188/


All Articles