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.

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

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.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
JavaScript Forms Form Validation Cookies CGI Programs.
Web-based Application Development Lecture 20 April 4, 2006 Anita Raja.
Servlets and a little bit of Web Services Russell Beale.
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
HTTP Cookie CSC 667/867. PERSISTENT CLIENT STATE HTTP COOKIES Cookies are a general mechanism which server side connections (such as CGI scripts) can.
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.
Rensselaer Polytechnic Institute CSC-432 – Operating Systems David Goldschmidt, Ph.D.
 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.
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.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
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.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
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.
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 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
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.
Introduction to Client-Side Web Development Introduction to Client-Side programming using JavaScript JavaScript; application examples 10 th February 2005.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
A Little Bit About Cookies Fort Collins, CO Copyright © XTR Systems, LLC A Little Bit About Cookies Instructor: Joseph DiVerdi, Ph.D., M.B.A.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
JavaScript Part 9 George Mason University June 23, 2010.
SE-2840 Dr. Mark L. Hornick1 Servlet Threads and Sessions.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
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.
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.
(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
©SoftMooreSlide 1 Cookies. ©SoftMooreSlide 2 Cookies Basic idea –web application sends a simple name/value pair to the client –when the client connects.
Project 5: Customizing User Content Essentials for Design JavaScript Level Two Michael Brooks.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
Server side. Internet technologies – Ohad © Server-side processing approaches  Server-side UI generation  PHP/ASP.net/JSP  Single Page Application.
Programming for the Web Cookies & Sessions Dónal Mulligan BSc MA
National College of Science & Information Technology.
Cookies Tutorial Cavisson Systems Inc..
CSE 154 Lecture 20: Cookies.
JavaScript, Sixth Edition
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.
Cookies and JavaScript
CSE 597B Computational Issues in Ecommerce
What is Cookie? Cookie is small information stored in text file on user’s hard drive by web server. This information is later used by web browser to retrieve.
Session Tracking Techniques
HTML5 and Local Storage.
CSc 337 Lecture 27: Cookies.
CSc 337 Lecture 25: Cookies.
Presentation transcript:

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 can be placed in the cookies.txt file two ways: by the client using Javascript by the server placing the cookie in the HTTP Response Header –in this case, you’ll usually be asked it its OK to save the cookie by your browser –the “tarball” consists of name value pairs

Cookie facts Cookies are domain specific cookie information can only be retrieved by servers in the same domain that set the cookie; If you set a cookie from Javascript it can only be retrieved by Javascript Cookies are properties of documents ( there is a document.cookie) Cookie records can contain: –cookie domain (domain of the server) –whether it need a sucure connection to access the cookie –pathname of URL capable of accessing the cookie –expiration date –name/value pairs

Cookie limitations Not everyone has a cookie-friendly browser (but most people do). Not everyone who has a cookie-friendly browser will accept your cookies (but most people will). Each domain is allotted only 20 cookies (on a specific client machine), so use them sparingly. Cookies must be no larger than 4 KB. That's just over 4,000 characters, which is plenty.

Life Cycle of Cookies When you start up your browser the contents of cookies.txt is loaded into memory during a browser session, cookies (including new ones) are kept in memory for speed reasons in memory cookies are written to cookies.txt when you shut down the browser cookies without expiration dates won’t be written to cookies.txt cookies with expiration dates will be persistent in cookies.txt until Netscape removed (when they expire)

Setting cookies Setting cookies is more frequently done by servers passing a cookie in the HTTP response header assign the information to document.cookie –successive assignments are not destructive, they keep appending to what is already there –Javascript limits what you can assign from the client as follows: Document.cookie = “cookieName = cookieData [ ; expires = timeInGMTString] [ ; path = pathName ] [ ; domain = domainName ] [ ; secure ]

More... Name/data - each cookie must have a name and data; data can contain no spaces (this implies URL encoding, use function escape( ) and unescape( ) expires - must be in GMT format (use toGMTString function); if expires is omitted cookie is temporary and won’t be written to cookies.txt path - for client side cookies just use the default Domain - to help synchronize cookie data across a set of documents for the specified domain (this is known as the cookie domain) SECURE - this is really for server-side cookies, so omit it.

Multiple name/value pairs If you want to save multiple name value pairs make sure you separate them with some character so you can parse them out (like a “:”) Function getCookieData(label) { var labelLen = label.length var cLen = document.cookie.length var I = 0 var cEnd while ( i < cLen) { var j = I + labelLen if ( document.cookie.substring( I, j ) == label ) { cEnd = document.cookie.indexOf (“:”), j) if (cEnd = = -1 ) { cEnd = document.cookie.length } return unescape(document.cookie.substring(j,cEnd) } i++ } return “ “ }