- Cookies: Small piece of data stored in the user's computer by the web browser while browsing a website. Cookies were designed to be a reliable mechanism for websites to remember stateful information or to record the user's browsing activity.
- Local Storage: The localStorage and sessionStorage properties allow to save key/value pairs in a web browser. The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.
- Session Storage: The sessionStorage object stores data only for a session, meaning that the data is stored until the browser (or tab) is closed.
- IndexedDB: IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data.
- Web SQL: Web SQL Database is a web page API for storing data in databases that can be queried using a variant of SQL. The API is supported by Google Chrome, Opera, Safari, and the Android Browser.
go to notes for more details. && HTTP & Cookies Must watch advanced
- 4kb size limit
- First party(user data) and 3ed party cookies(ads).
- can be read and write by client-side and server-side.
- can be read by the clients.
document.cookie
setcookie(name, value, expire, path, domain, secure, httponly);
$_COOKIE[name]
setcookie("user","Yahoo",time() + (86400*30),"/",domain="True(default)",secure,httponly);
$_COOKIE["user"] // Yahoo to check|| if isset($_COOKIE["user"]) echo "set" else "not"
go to notes for more details. && Sessions
- A session is a way to store information (in variables) to be used across multiple pages.
- Unlike a cookie, the information is not stored on the users computer.
- session storage get's cleared when the browser is closed.
- session data is stored on the server.
- 5mb size limit.
- it works per window
session_start();
$_SESSION[name] = value;
$_SESSION["favcol"] = "orange";
print_r($_SESSION); -> Array([favcol]=>orange)
session_unset(); // remover all session variables
session_destroy();
- local storage data is cleared if the page is closed.
- does not expire. need to manually remove.
- 5mb size limit.
- only localstorage can be read by the clients.
localStorage.setItem("name", "John");
localStorage.getItem("name");
localStorage.removeItem("name");
localStorage.clear();
Difference between: YT