CHAP 6. USING THE HTML5 WEB STORAGE API.  Cookie - Are a built-in way of sending text values back and forth from server to client.  Servers can use.

Slides:



Advertisements
Similar presentations
Not like the State of Virginia. What is State in ASP.NET? Services (like web services) are Stateless. This means if you make a second request to a server,
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
® Microsoft Office 2010 Browser and Basics.
HTML5 Storage. Why Local Storage? Data accessed over the internet can never be as fast as accessing data locally Data accessed over internet not secure.
Servlets and a little bit of Web Services Russell Beale.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
Chapter 10 Maintaining State Information Using Cookies.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
 A cookie is a piece of text that a Web server can store on a user's hard disk.  Cookie data is simply name-value pairs stored on your hard disk by.
Chapter 25 Utilizing Web Storage.
Martin Kruliš by Martin Kruliš (v1.0)1.
Khan Academy Eric Fouh CS6604 Spring 2012 January 25, 2012.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
JavaScript, Fourth Edition
Advanced Web Forms with Databases Programming Right from the Start with Visual Basic.NET 1/e 13.
Chapter 8 Cookies And Security JavaScript, Third Edition.
12/3/2012ISC329 Isabelle Bichindaritz1 PHP and MySQL Advanced Features.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Cookies Web Browser and Server use HTTP protocol to communicate and HTTP is a stateless protocol. But for a commercial website it is required to maintain.
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
The business logic engine for Microsoft IIS Speaker T.M. Arnett.
Session and Cookie Management in.Net Sandeep Kiran Shiva UIN:
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
PHP. $_GET / $_POST / $_SESSION PHP uses predefined variables to provide access to important information about the server and requests from a browser.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Web Database Programming Week 7 Session Management & Authentication.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
Internet & World Wide Web How to Program, 5/e. 2.
XP Browser and Basics COM111 Introduction to Computer Applications.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
HTML 5 Tutorial Chapter 6 Web Storage. Storing Data on The Client HTML5 offers two new objects for storing data on the client: localStorage - stores data.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
CS2550 Dr. Brian Durney. SOURCES  JavaScript: The Definitive Guide, by David Flanagan  Dive into HTML5, by Mark Pilgrim
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
Web Technologies Lecture 6 State preservation. Motivation How to keep user data while navigating on a website? – Authenticate only once – Store wish list.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
COOKIES Gloria Soria Network Security COSC 356. What is a Cookie? A cookie is a piece of text that a Web Server can store on a user's hard disk. Cookies.
PHP: Further Skills 02 By Trevor Adams. Topics covered Persistence What is it? Why do we need it? Basic Persistence Hidden form fields Query strings Cookies.
ASP.NET State Management Overview Prepared By Manish Kumar Aery(IM66) Department of computer Application IET Bhaddal (Ropar)
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Phonegap Bridge – Storage CIS 136 Building Mobile Apps 1.
Web Storage and Cookies Cookies, Local and Session Storage SoftUni Team Technical Trainers Software University
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Storing Data.
Managing State Chapter 13.
CIS 136 Building Mobile Apps
The Application Lifecycle
Web Systems Development (CSC-215)
Flight prices.
CIS 136 Building Mobile Apps
HTML5 and Local Storage.
Hyper Text Transfer Protocol
Building ASP.NET Applications
HTML5 and Local Storage.
Presentation transcript:

CHAP 6. USING THE HTML5 WEB STORAGE API

 Cookie - Are a built-in way of sending text values back and forth from server to client.  Servers can use the values they put into these cookies to track user information across web pages.  Cookies have some well-known drawbacks:  Cookies are extremely limited in size.  Only about 4KB of data can be set  Cookies are transmitted back and forth from server to browser on every request scoped to that cookie.  Cookie data is visible on the network, making them a security risk when not encrypted  Any data persisted as cookies will be consuming network bandwidth every time a URL is loaded. COOKIE

 It is very common for users to open multiple windows as they shop for travel deals, comparing flights from different vendors for the same departure time.  If a user switches back and forth between browser windows while comparing prices and availability, they are likely to set cookie values in one window that will be unexpectedly applied to another window served from the same URL on its next operation. PLUGGING DATA LEAKS

PLUGGING DATA LEAKS (CONT.) Saturday

 By using either sessionStorage or localStorage  Developers can choose to let those values survive either across page loads in a single window or tab or across browser restarts, respectively.  Stored data is not transmitted across the network, and is easily accessed on return visits to a page  Larger values can be persisted using the Web Storage API values as high as a few megabytes. WEB STORAGE

CHECKING FOR BROWSER SUPPORT function checkStorageSupport() { //sessionStorage if (window.sessionStorage) { alert('This browser supports sessionStorage'); } else { alert('This browser does NOT support sessionStorage'); } //localStorage if (window.localStorage) { alert('This browser supports localStorage'); } else { alert('This browser does NOT support localStorage'); }

 The object implementing the Web Storage API is attached to the window, so window.sessionStorage contains the functions you need to call.  Setting  Retrieving SETTING AND RETRIEVING VALUES window.sessionStorage.setItem(‘myFirstKey’, ‘myFirstValue’); alert(window.sessionStorage.getItem(‘myFirstKey’));

sessionStoragelocalStorage Values persist only as long as the window or tab in which they were stored. Values persist beyond window and browser lifetimes. Values are only visible within the window or tab that created them. Values are shared across every window or tab running at the same origin. LOCAL VERSUS SESSION STORAGE

WEB STORAGE API ATTRIBUTES AND FUNCTIONS interface Storage { readonly attribute unsigned long length; getter DOMString key(in unsigned long index); getter any getItem(in DOMString key); setter creator void setItem(in DOMString key, in any data); deleter void removeItem(in DOMString key); void clear(); };

 To register to receive the storage events of a window’s origin, simply register an event listener  window.addEventListener("storage", displayStorageEvent, true); COMMUNICATING WEB STORAGE UPDATES // display the contents of a storage event function displayStorageEvent(e) { var logged = "key:" + e.key + ", newValue:" + e.newValue + ", oldValue:" + e.oldValue +", url:" + e.url + ", storageArea:" + e.storageArea; alert(logged); }

 Although the specification for HTML5 Web Storage allows for objects of any type to be stored as keyvalue pairs, in current implementations, some browsers limit values to be text string data types.  JSON is a standard for data-interchange that can represent objects as strings and vice-versa.  We can use it to serialize complex objects in and out of Web Storage in order to persist complex data types. JSON OBJECT STORAGE

JSON OBJECT STORAGE (CONT.) var data; function loadData() { data = JSON.parse(sessionStorage["myStorageKey"]) } function saveData() { sessionStorage["myStorageKey"] = JSON.stringify(data); } window.addEventListener("load", loadData, true); window.addEventListener("unload", saveData, true);

 Write an todo list function that can save permeantly using localStorage. PRACTICE