Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does HTML5 local storage separate data per user?

If a website stores a value in local storage for a user on a machine, then later another user signs onto that machine and browses to the site, will the site see and overwrite the first user's value, or will local storage be empty because it's a different user?

(This is a similar question, but no one ever answers the first part: How to deal with localStorage for multiple users?)

like image 435
Richard Avatar asked Aug 07 '15 06:08

Richard


People also ask

Is localStorage shared between users?

The main features of localStorage are: Shared between all tabs and windows from the same origin. The data does not expire. It remains after the browser restart and even OS reboot.

Is local storage user specific?

localStorage data is specific to the protocol of the document. In particular, for a site loaded over HTTP (e.g., http://example.com ), localStorage returns a different object than localStorage for the corresponding site loaded over HTTPS (e.g., https://example.com ).

How is data stored in HTML5 storage?

What is HTML Web Storage? With web storage, web applications can store data locally within the user's browser. Before HTML5, application data had to be stored in cookies, included in every server request. Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance.

What is true with local storage in HTML5?

It is described in the HTML5 specifications. Local storage is mainly used to store and retrieve data in HTML pages from the same domain. Even after restarting a browser, the data can be recovered from all windows in the same domain. This type of storage offers numerous options for Web apps.


2 Answers

To clarify: the OP is asking what happens with localStorage when two user profiles access the same site. The quick answer: they do not collide.

localStorage is stored separately for each browser user profile, just like cookies, passwords, stored form data, etc. If two people log into different accounts on a shared computer and both visit the same site, each person's localStorage data will be stored in a separate place.

However, this should not be used to store sensitive data! Also, when a user logs out the localStorage will still be there.

Here is a jsfiddle.

like image 120
JosiahDaniels Avatar answered Sep 22 '22 12:09

JosiahDaniels


LocalStorage is a simple key-value store, in which the keys and values are strings. There is only one store per domain. This functionality is exposed through the globally available localStorage object. The same applies to sessionStorage.

There aren't user storage component provided by the localStorage system, but if you need you can manage in your html page using javascript

<script>

    // Using localStorage
    // store data
    localStorage.lastName = "LastName";
    localStorage.firstName = "FirstName";
    localStorage.location = "Location";
    // retrieve data
    var lastName = localStorage.lastName;
    var firstName = localStorage.firstName;
   var location = localStorage.location;
</scipt>

this w3c resource and this from html5rocks could be useful

like image 45
ScaisEdge Avatar answered Sep 24 '22 12:09

ScaisEdge