Copyright ©2005  Department of Computer & Information Science Working with Cookies.

Slides:



Advertisements
Similar presentations
CookiesPHPMay-2007 : [‹#›] Maintaining State in PHP Part I - Cookies.
Advertisements

UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
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.
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.
Creating Databases for Web Applications Courses example Persistent information. Cookies. Session Homework: Examine a computer (your own or in a lab) for.
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.
Cookies Purpose –Write information that lives after the browser exits –Keep track of form data submitted multiple times during a particular visit –Track.
6/10/2015Cookies1 What are Cookies? 6/10/2015Cookies2 How did they do that?
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.
Web-based Application Development Lecture 20 April 4, 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.
Chapter 10 Managing State Information PHP Programming with MySQL.
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.
Cookies Set a cookie – setcookie() Extract data from a cookie - $_COOKIE Augment user authentication script with a cookie.
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.
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.
CSE 154 LECTURE 12: COOKIES. Including files: include include("filename"); PHP include("header.html"); include("shared-code.php"); PHP inserts the entire.
Web Programming Language Week 7 Dr. Ken Cosh Security, Sessions & Cookies.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Maintaining State MacDonald Ch. 9 MIS 324 MIS 324 Professor Sandvig Professor Sandvig.
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.
Cookies & Session Web Technology
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
PHP Programming with MySQL Slide 10-1 CHAPTER 10 Managing State Information.
COOKIES and SESSIONS. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
The Web Wizard’s Guide To JavaScript Chapter 7 Cookies: Maintaining State.
JavaScript Part 9 George Mason University June 23, 2010.
PHP Cookies. Cookies are small files that are stored in the visitor's browser. Cookies can be used to identify return visitors, keep a user logged into.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Persistence Maintaining state using cookies and queries.
Cookies (continue). Extracting Data From Cookies Data retrieved from a cookie is a simple text string. While there is no specific JavaScript function.
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)
Introduction to Programming the WWW I CMSC Summer 2003 Lecture 13.
 A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests.
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.
Cookies and Sessions in PHP. Arguments for the setcookie() Function There are several arguments you can use i.e. setcookie(‘name’, ‘value’, expiration,
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.
Sessions and cookies (part 2) MIS 3501, Fall 2015 Brad N Greenwood, PhD Department of MIS Fox School of Business Temple University 11/19/2015.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● / www,histpk.org Hidaya Institute of Science & 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.
Sessions and cookies (part 2)
Client / Session Identification Cookies
Web Programming Language
Cookies and Sessions in PHP
Implementing Cookies in PHP
Cookies and JavaScript
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.
<?php require("header.htm"); ?>
Cookies Cookie :- A cookie is often used to identify a user. A cookie is often used to identify a user. A cookie is a small file that the server embeds.
CSc 337 Lecture 27: Cookies.
Web Programming Language
Advanced Concepts and AJAX
CSc 337 Lecture 25: Cookies.
Presentation transcript:

Copyright ©2005  Department of Computer & Information Science Working with Cookies

Copyright ©2005  Department of Computer & Information Science Goals By the end of this lecture you should … Understand the different types of cookies.Understand the different types of cookies. Understand how JavaScript keeps track of cookies using the document.cookie object.Understand how JavaScript keeps track of cookies using the document.cookie object. continued …

Copyright ©2005  Department of Computer & Information Science Goals By the end of this lecture you should … Understand how to create new cookies.Understand how to create new cookies. Understand how to set an expiration date for a cookie.Understand how to set an expiration date for a cookie. Understand how to delete a cookie.Understand how to delete a cookie. Understand how to update a cookie’s value.Understand how to update a cookie’s value.

Copyright ©2005  Department of Computer & Information Science What is a Cookie? A cookie is a small text file that JavaScript can use to store customized information about a user.A cookie is a small text file that JavaScript can use to store customized information about a user. There are two types of cookies:There are two types of cookies: –Session Cookies (aka Transient Cookies) –Persistent Cookies

Copyright ©2005  Department of Computer & Information Science Session Cookies A browser stores session cookies in memory.A browser stores session cookies in memory. Once a browser session ends, browser loses the contents of a session cookie.Once a browser session ends, browser loses the contents of a session cookie.

Copyright ©2005  Department of Computer & Information Science Persistent Cookies Browsers store persistent cookies to a user’s hard drive.Browsers store persistent cookies to a user’s hard drive. We can use persistent cookies to customize information about a user that we can use when the user returns to a website at a later date.We can use persistent cookies to customize information about a user that we can use when the user returns to a website at a later date.

Copyright ©2005  Department of Computer & Information Science Cookies as Objects JavaScript deals with cookies as objects.JavaScript deals with cookies as objects. Specifically, JavaScript works with cookies using the document.cookie attribute.Specifically, JavaScript works with cookies using the document.cookie attribute. We can read information from cookies by examining the document.cookie object.We can read information from cookies by examining the document.cookie object.

Copyright ©2005  Department of Computer & Information Science Examples of Cookie Uses User preferencesUser preferences Saving form dataSaving form data Assisting with conveying information to back-end programsAssisting with conveying information to back-end programs Tracking online shopping habitsTracking online shopping habits

Copyright ©2005  Department of Computer & Information Science Parts of a Cookie Object name – An identifier by which we reference a particular cookie.name – An identifier by which we reference a particular cookie. value – The information we wish to save, in reference to a particular cookie.value – The information we wish to save, in reference to a particular cookie. expires – A GMT-formatted date specifying the date (in milliseconds) when a cookie will expire.expires – A GMT-formatted date specifying the date (in milliseconds) when a cookie will expire.

Copyright ©2005  Department of Computer & Information Science Parts of a Cookie Object path – Specifies the path of the web server in which the cookie is valid. By default, set to the path of the page that set the cookie. However, commonly specified to /, the root directory.path – Specifies the path of the web server in which the cookie is valid. By default, set to the path of the page that set the cookie. However, commonly specified to /, the root directory. domain – Specifies the domain for which the cookie is valid. Set, by default, only to the full domain of a page. You may wish to extend the domain to include other computers in your domain.domain – Specifies the domain for which the cookie is valid. Set, by default, only to the full domain of a page. You may wish to extend the domain to include other computers in your domain. secure – Specifies that a web browser needs a secure HTTP connection to access a cookie.secure – Specifies that a web browser needs a secure HTTP connection to access a cookie.

Copyright ©2005  Department of Computer & Information Science Cookie Limitations A given domain may only set 20 cookies per machine.A given domain may only set 20 cookies per machine. A single browser may only store 300 cookies.A single browser may only store 300 cookies. Browsers limit a single cookie to 4KB.Browsers limit a single cookie to 4KB.

Copyright ©2005  Department of Computer & Information Science Setting a Cookie – General Form window.document.cookie = “cookieName = cookieValue [; expires = expireDate] [; path = pathName] [; domain = domainName] [; secure]”;

Copyright ©2005  Department of Computer & Information Science Escape Sequences When we set cookie values, we must first convert the string values that set a cookie so that the string doesn’t contain white space, commas or semi-colons.When we set cookie values, we must first convert the string values that set a cookie so that the string doesn’t contain white space, commas or semi-colons. We can use JavaScript’s intrinsic escape() function to convert white space and punctuation with escape sequences.We can use JavaScript’s intrinsic escape() function to convert white space and punctuation with escape sequences. Conversely, we can use unescape() to view text encoded with escape().Conversely, we can use unescape() to view text encoded with escape().

Copyright ©2005  Department of Computer & Information Science Using the Cookie Library A great, open-source, tool is Bill Dortch’s Cookie Library, which contains a plethora of useful functions for dealing with cookies.A great, open-source, tool is Bill Dortch’s Cookie Library, which contains a plethora of useful functions for dealing with cookies. To use the functions, include the syntax on the next slide in your scripts …To use the functions, include the syntax on the next slide in your scripts …

Copyright ©2005  Department of Computer & Information Science Including the Cookie Library </script>

Copyright ©2005  Department of Computer & Information Science Calculation Expiration Dates JavaScript stores dates as the number of milliseconds since 01/01/1970.JavaScript stores dates as the number of milliseconds since 01/01/1970. To calculate a new date, we would use a formula derived from milliseconds.To calculate a new date, we would use a formula derived from milliseconds. For example, 1 year in milliseconds: year = (365 * 24 * 60 * 60 * 1000)For example, 1 year in milliseconds: year = (365 * 24 * 60 * 60 * 1000)

Copyright ©2005  Department of Computer & Information Science Calculating Expiration Dates var dNow = new Date(); var intTime = new Number(); intTime = dNow.getTime() + (365 * 24 * 60 * 60 * 1000); var dExpire = new Date(intTime);

Copyright ©2005  Department of Computer & Information Science Calling SetCookie() We can call the SetCookie() function from the Cookie Library using the following syntax: SetCookie(name, value [, expires] [, path] [, domain] [, secure]);We can call the SetCookie() function from the Cookie Library using the following syntax: SetCookie(name, value [, expires] [, path] [, domain] [, secure]);

Copyright ©2005  Department of Computer & Information Science Open the file called usingCookies_01.html

Copyright ©2005  Department of Computer & Information Science Calling GetCookie() We can call the GetCookie() function from the Cookie Library using the following syntax: GetCookie(cookieName);We can call the GetCookie() function from the Cookie Library using the following syntax: GetCookie(cookieName);

Copyright ©2005  Department of Computer & Information Science Open the file called usingCookies_02.html

Copyright ©2005  Department of Computer & Information Science Calling DeleteCookie() We can call the DeleteCookie() function from the Cookie Library using the following syntax: DeleteCookie(name, [, path] [, domain]);We can call the DeleteCookie() function from the Cookie Library using the following syntax: DeleteCookie(name, [, path] [, domain]);

Copyright ©2005  Department of Computer & Information Science Open the file called usingCookies_03.html

Copyright ©2005  Department of Computer & Information Science Modifying a Cookie We can call the SetCookie() function from the Cookie Library to modify a cookie, essentially overwriting the previous cookie.We can call the SetCookie() function from the Cookie Library to modify a cookie, essentially overwriting the previous cookie.

Copyright ©2005  Department of Computer & Information Science Open the file called usingCookies_04.html

Copyright ©2005  Department of Computer & Information Science Summary Session cookies are available to a browser so long as a browser session is active; once the browser closes, it loses all session cookies.Session cookies are available to a browser so long as a browser session is active; once the browser closes, it loses all session cookies. Browsers save persistent cookies to a user’s hard drive; the values of persistent cookies are available across multiple browser sessions.Browsers save persistent cookies to a user’s hard drive; the values of persistent cookies are available across multiple browser sessions. continued …

Copyright ©2005  Department of Computer & Information Science Summary Cookies consist of a name, value, expiration date, path, domain and secure flag.Cookies consist of a name, value, expiration date, path, domain and secure flag. Browsers store cookie modification dates in milliseconds, from 01/01/1970.Browsers store cookie modification dates in milliseconds, from 01/01/1970. continued …

Copyright ©2005  Department of Computer & Information Science Summary We can use the SetCookie() function from the open-source Cookie Library to set or modify a cookie.We can use the SetCookie() function from the open-source Cookie Library to set or modify a cookie. We can use the GetCookie() function from the open-source Cookie Library to retrieve an existing cookie’s value.We can use the GetCookie() function from the open-source Cookie Library to retrieve an existing cookie’s value. We can use the DeleteCookie() function from the open-source Cookie Library to delete a cookie.We can use the DeleteCookie() function from the open-source Cookie Library to delete a cookie.

Copyright ©2005  Department of Computer & Information Science Resources Spain-McDuffie, Tina. JavaScript Concepts & Techniques: Programming Interactive Web Sites. Wilsonville, OR: Franklin, Beedle & Associates, 2003.Spain-McDuffie, Tina. JavaScript Concepts & Techniques: Programming Interactive Web Sites. Wilsonville, OR: Franklin, Beedle & Associates, 2003.