Web Storage IDIA 619 Spring 2013 Bridget M. Blodgett.

Slides:



Advertisements
Similar presentations
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
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.
JavaScript and AJAX Jonathan Foss University of Warwick
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Tutorial 14 Working with Forms and Regular Expressions.
Session Management A290/A590, Fall /25/2014.
CSE 154 LECTURE 13: SESSIONS. Expiration / persistent cookies setcookie("name", "value", expiration); PHP $expireTime = time() + 60*60*24*7; # 1 week.
 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.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Practical PHP IDIA Spring 2012 Bridget M. Blodgett.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
Tutorial 14 Working with Forms and Regular Expressions.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
JavaScript, Fourth Edition
Advanced Web Forms with Databases Programming Right from the Start with Visual Basic.NET 1/e 13.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
Getting Started with Canvas IDIA Spring 2013 Bridget M. Blodgett.
CS453: State in Web Applications (Part 1) State in General Sessions (esp. in PHP) Prof. Tom Horton.
USING PERL FOR CGI PROGRAMMING
HTML5. HTML5’s overall theme The browser as a rich application platform rich, cross-device user interfaces offline operation capability hardware access.
Chapter 8 Cookies And Security JavaScript, Third Edition.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
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.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
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.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
The Problem of State. We will look at… Sometimes web development is just plain weird! Internet / World Wide Web Aspects of their operation The role of.
CS2550 Dr. Brian Durney. SOURCES  JavaScript: The Definitive Guide, by David Flanagan  Dive into HTML5, by Mark Pilgrim
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
(Some from Chapter 11.9 – “Web” 4 th edition and
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
IS2802 Introduction to Multimedia Applications for Business Lecture 8: JavaScript and Cookies Rob Gleasure
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
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.
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
Storing Data.
Managing State Chapter 13.
Web Systems Development (CSC-215)
HTML5 and Local Storage.
CSE 154 Lecture 22: Sessions.
Training & Development
HTML5 and Local Storage.
Presentation transcript:

Web Storage IDIA 619 Spring 2013 Bridget M. Blodgett

Cookies and XML Previously the main way of storing information semi- permanently in a web page was to set a cookie They have size limitations Many users disable them They aren't very secure and couldn't be used for storing sensitive information The files could be no bigger than 4k because they are passed as part of the HTTP header information

HTML5 Web Storage Still operates in the keyword => value pairing style Offers up to 5 mb of storage within the browser This is a per domain amount and each browser keeps separate storage space Since the information is stored on the browser it doesn't need to be passed back and forth between the server and the browser to be interpreted by JavaScript Try adding the following into a blank JS & HTML file: localStorage.setItem("sticky_0", "Pick up dry cleaning");

Retrieving Data To pull data back out of the local storage you just need to remember the key word which you assigned to it var sticky = localStorage.getItem("sticky_0"); This data can then be manipulated like regular text data to display it on the screen or other items. If you write data to the same key only the last recorded item will be saved (it overwrites the ones before it) The data that can be stored is restricted to string types JS will try and convert any other types you put into local storage to strings

Converting Types If you want to store non-string data you will need to convert the string local storage returns back to the type you need Functions like parseInt() and parseFloat() can be passed the local storage output to convert it to the type you want var store = parseInt(localStorage.getItem(“numItems”));

Local Storage & Arrays Local storage can be treated as an associative array localStorage["sticky_0"] = "Pick up dry cleaning"; So you can treat local storage like other arrays This allows you to use either the array or the built in methods to save data to the local storage Even mixing and matching is fine With some manipulation you can store array data in the local storage as well

Saving an Array By combining local storage with JSON you can convert your arrays to a string to save By passing your array to the.stringify() method the output is converted to a string with you can then store To take the data back out of the local storage you can run it through the parse() method to convert it back to an array var stickiesarray = getStickiesarray(); localStorage.setItem(key, value); stickiesarray.push(key); localStorage.setItem("stickiesarray",JSON.stringify(sticki esarray));

Additional Properties & Methods Local Storage has one additional property and one method in its API The length property tells you how many keys are currently stored (for your domain) The key method pulls the key (unique id) for each stored value You don't have to remember or know all of them! for (var i = 0; i < localStorage.length; i++) { var key = localStorage.key(i); var value = localStorage[key]; alert(value); }

Removing Data Beyond using the browser's built in data management tools there are two additional methods for removing data Clear will remove all locally stored data for your domain RemoveItem works like addItem but finds the matching key and deletes both it and the data it contains from the browser

Making Unique Variables You can make new unique variables by integrating some additional features for JS You can append the current time onto the variable end It will never repeat var currentDate = new Date(); var time = currentDate.getTime(); var key = "sticky_" + time;

function createSticky() { var stickiesarray = getStickiesarray(); var currentDate = new Date(); var key = "sticky_" + currentDate.getTime(); var value = document.getElementById("note_text").value; localStorage.setItem(key, value); stickiesarray.push(key); localStorage.setItem("stickiesarray", JSON.stringify(stickiesarray)); addStickyToDOM(value); }

function deleteSticky(key) { localStorage.removeItem(key); var stickiesarray = getStickiesarray(); if (stickiesarray) { for (var i = 0; i < stickiesarray.length; i++) { if (key == stickiesarray[i]) { stickiesarray.splice(i,1); } localStorage.setItem("stickiesarray", JSON.stringify(stickiesarray)); }

Session Storage Session storage allows you to store information for only one use of the browser (called a session) The same API is used for session storage and supports all of the same methods and properties However any information left in storage when the browser is closed is automatically deleted