Web-based Application Development Lecture 20 April 4, 2006 Anita Raja.

Slides:



Advertisements
Similar presentations
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.
Advertisements

JavaScript and AJAX Jonathan Foss University of Warwick
Cookies The HTTP protocol is stateless, that is, it does not maintain information on states after the session ends. But sometimes it is useful to remember.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming cookies.
The Web Warrior Guide to Web Design Technologies
1 Configuring Internet- related services (April 22, 2015) © Abdou Illia, Spring 2015.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
Cookies Purpose –Write information that lives after the browser exits –Keep track of form data submitted multiple times during a particular visit –Track.
Web-based Application Development Lecture 9 February 7, 2006 Anita Raja.
Lesson 8 Cookies. What is a cookie A little “tarball” of information stored on the client machine’s hard drive. –Usually in the cookies.txt file –information.
JavaScript Forms Form Validation Cookies CGI Programs.
B118 Web Programming Session #9 Client/Server & Cookies April 5, 2004.
Web-based Application Development Lecture 17 March 16, 2006 Anita Raja.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Web-based Application Development Lecture 18 March 21, 2006 Anita Raja.
20/1/12.  Cookies are a useful way of storing information on the client’s computer  Initially feared, when they first appeared and were considered a.
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Web-based Application Development Lecture 19 March 23, 2006 Anita Raja.
Web Storage IDIA 619 Spring 2013 Bridget M. Blodgett.
Client-Side programming with JavaScript 3
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 12.
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.
Cookies and Security Saving the “state”
JavaScript, Fourth Edition
Working with Cookies Managing Data in a Web Site Using JavaScript Cookies* *Check and comply with the current legislation regarding handling cookies.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Week 9 PHP Cookies and Session Introduction to JavaScript.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
USING PERL FOR CGI PROGRAMMING
Chapter 8 Cookies And Security JavaScript, Third Edition.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
1 CS 21A Beginning JavaScript Programming Project 4 Cookies, Arrays, and Frames Sonny Huang.
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
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.
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
The Web Wizard’s Guide To JavaScript Chapter 7 Cookies: Maintaining State.
JavaScript Part 9 George Mason University June 23, 2010.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Persistence Maintaining state using cookies and queries.
Copyright ©2005  Department of Computer & Information Science Working with Cookies.
Cookies (continue). Extracting Data From Cookies Data retrieved from a cookie is a simple text string. While there is no specific JavaScript function.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Cookies. Cookie A cookie is a method for a Web server to maintain state information about users as users navigate different pages on the site, and as.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
(Some from Chapter 11.9 – “Web” 4 th edition and
IS2802 Introduction to Multimedia Applications for Business Lecture 8: JavaScript and Cookies Rob Gleasure
Review and Practice for Final exam. Final exam Date: December 20, 3:15 – 5:15pm Format: Two parts: First part: multiple-choice questions (13 questions.
Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks.
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.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Cookies in PHP CPTE 212 4/7/2015 John Beckett. Two Types of Cookies A cookie is data saved on the client computer Temporary – saved in RAM in the workstation.
JavaScript, Sixth Edition
Programming the Web using XHTML and JavaScript
JavaScript Objects.
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
PHP Introduction.
Intro to PHP & Variables
Cookies and JavaScript
Objectives Insert a script element Write JavaScript comments
WEB PROGRAMMING JavaScript.
Configuring Internet-related services
CSc 337 Lecture 27: Cookies.
JavaScript: Introduction to Scripting
Advanced Concepts and AJAX
CIS 136 Building Mobile Apps
CSc 337 Lecture 25: Cookies.
Presentation transcript:

Web-based Application Development Lecture 20 April 4, 2006 Anita Raja

Cookies Persistent data is data that exists over a long term Data created and manipulated in a JavaScript program ceases to exist when the containing Web page is changed Problem: How can we maintain data over a long period of time?

Cookies Why not write to the user’s hard drive? Security! Imagine if any Web page you accessed could write data/programs to your hard drive Instead …

Cookies A string stored in a special format May be persistent or temporary Small file (2,000 – 4,000 characters max.) Not more than a certain number from any one Internet domain (300 for Netscape) Create a cookie by assigning a string value to the cookie property of the document object

Cookies A cookie string consists of five parts in the following order: The cookie’s name and its value Expiration date Pathname of the Web page creating the cookie Domain name of the server creating the cookie Security parameter to restrict access

Cookies For example, creating only the first part (name and value): document.cookie = “userName=Fred” Cookie Name Value Creates a cookie named userName whose value is Fred

Cookies Setting the expiration date requires storing two data items in the cookie: Name and value Expiration date Expiration date must be specified as Greenwich Mean Time (GMT)

Cookies Browsers store time as the number of milliseconds (thousandths of a second) from January 1, 1970 to now When we create a new Date object, the browser sets its value to the number of milliseconds from 1/1/1970.

Cookies To change the value of a date object we need to add a certain number of milliseconds to it: Compute milliseconds Assign new value to the date object The getTime() method of a date object returns the current date in millisecond format Ch15-Script-06

Cookies Now all we have to do is compute the number of milliseconds from now until the cookie should expire For a 30-day expiration that’s: 30 * 24 * 60 * 60 * 1000

Cookies To create an expiration date: var expDate = new Date() var currentDate = expDate.getTime() var thirtyDays = 30*24*60*60*1000 var fromNow = currentDate + thirtyDays

Cookies Now set the date object to that value using the setTime method: expDate.setTime(fromNow) Ch15-Script-07

Cookies More compactly: var expDate = new Date() expDate.setTime(expDate.getTime()+ 30*24*60*60*1000)

Cookies JavaScript also provides: A setMonth() method to set month values directly … Ch15-Script-08 As well as a toGMTString() method to convert date/time strings directly to GMT format

Cookies Once you’ve established a cookie’s expiration date you assign it to a cookie: var expDate = new Date() var currentMonth = expDate.getMonth() expDate.setMonth(currentMonth+1) document.cookie = ¬ “userName=Fred;expires=“+expDate.toGMTString()

Cookies However, JavaScript limited to reading only the “name=value” part of a cookie, not it’s expiration date How can you read the value of an existing cookie?

Cookies By using a method named split() that is common to all string objects The split() method requires a parameter that is used to parse a string into substrings at every location of the parameter

Cookies For example: var basicString = “alpha&beta&gamma” var thePieces = basicString.split(“&”) Creates an array of strings named thePieces such that: thePieces[0] = “alpha” thePieces[1] = “beta” thePieces[2] = “gamma”

Cookies Ch15-Script-09

Cookies How can we create multiple cookies? By assigning a new “name=value” to document.cookie There is only one document.cookie file But it can contain multiple “cookies”

Cookies document.cookie=“userName=Fred” document.cookie=“password=George” It looks like the second statement replaces the first document.cookie However, there is only one cookie So what really happens is that the two values are appended together Ch15-Script-10

Cookies To separate these into their constituent parts we execute a split twice Ch15-Script-11

Assignment Debugging Exercise, p. 446 Correct errors Post corrected document to your Web space as “Lagerstrom-Ch-15.html” Grade based on: Appearance Technical correctness of code Proper results