Cookies and JavaScript

Slides:



Advertisements
Similar presentations
CookiesPHPMay-2007 : [‹#›] Maintaining State in PHP Part I - Cookies.
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.
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.
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.
Web-based Application Development Lecture 20 April 4, 2006 Anita Raja.
Extras Plus! Pepper. Objectives extra knowledge Cookies Picture handling when creating site.
November 3, 2001ICTCM Conference1 Applied Calculus on the Web Applets & Applications Professor Michael S. Pilant Department of Mathematics Texas A&M University.
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.
11 CONFIGURE INTERNET EXPLORER Chapter 5. Chapter 5: Configure Internet Explorer2 CHAPTER OVERVIEW AND OBJECTIVES  Configuring Accessibility and Language.
The Internet & Web Browsers Business Webpage Design Kelly Seale.
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.
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.
Review and Practice for Final exam. Final exam Date: December 20, 3:15 – 5:15pm Format: Two parts: First part: multiple-choice questions (15 questions.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
1 Chapter 2 & Chapter 4 §Browsers. 2 Terms §Software §Program §Application.
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.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
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 Welcome to CSC 301 Web Programming Charles Frank.
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.
7 Chapter Seven Client-side Scripts. 7 Chapter Objectives Create HTML forms Learn about client-side scripting languages Create a client-side script using.
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.
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.
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)
PHP and Sessions. Session – a general definition The GENERAL definition of a session in the “COMPUTER WORLD” is: The interactions (requests and responses)
 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
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.
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.
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.
Programming for the Web Cookies & Sessions Dónal Mulligan BSc MA
File Uploads and Cookies Pat Morin COMP Outline File upload Cookies.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
CSE 154 Lecture 20: Cookies.
JavaScript, Sixth Edition
Browsing and Searching the Web
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
Cookies and Sessions in PHP
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.
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.
WEB PROGRAMMING JavaScript.
CSc 337 Lecture 27: Cookies.
JavaScript: Introduction to Scripting
Advanced Concepts and AJAX
CSc 337 Lecture 25: Cookies.
Presentation transcript:

Cookies and JavaScript References Appendix I in your book and Chapter 12 of JavaScriptWorld

Did you ever wonder? Did you ever wonder how a web site such as Yahoo! or Amazon.com remembers who you are and when you last logged in? These web sites leave a cookie in your computer.

What’s a Cookie? A piece of information that the browser stores in a text file in the user’s computer. A cookie identifies your computer to a web server A cookie can contain user info for their next visit to a web site Your username and when you last logged into Yahoo! Always includes the name of the server.

Where are your Cookies? Internet Explorer stores cookies in separate text files in a cookies folder, i.e. C:\Documents and Settings\User\Cookies\ Netscape and Mozilla store cookies in a single text file named cookie.txt. This is located deep in the file hierarchy in a location such as C:\Documents and Settings\User\ Application Data\Mozilla\Profiles\...\cookie.txt These examples apply to Win2000. In other Operating Systems, these locations will be different.

Netscape’s Cookie Manager Netscape has a nice Cookie Manager. See Netscape menu Tools > Cookie Manager You can use it to view and/or remove cookies, or to refuse cookies from certain sites.

Misconceptions - What cookies can’t do Cookies are text files, not programs Can’t read your hard disc Can’t transmit viruses

Storing multiple values The format is Document.cookie=“fieldname1=fieldvalue1; fieldname2=fieldvalue2; …” Total Cookie size <4K Max 300 cookies.

Typical Fields Name = text Expires = date Path = text Domain =text The Name parameter cannot contain spaces, commas or semicolons. The text contains the string stored. Expires = date expiration date (GMT). Expired cookies get deleted by the browser. If omitted, the cookie expires when the browser is closed. Path = text Indicates the path to which the cookie applies. “/” indicates the cookie can be accessed from any folder within the web site. Domain =text URL of web site storing the cookie Secure Indicates the data should be encrypted using a secure connection

JavaScript In JavaScript, you can refer to a cookie using document.cookie This is a string variable You can set this value or get it. document.cookie = str // set str = document.cookie // get You can use the split method with a delimiting string to split the cookie string can be split into an array of sub-strings.

Cookies and JavaScript JavaScript supplies a built-in object called document.cookie to handle cookie interaction. This object will store all the valid cookies for the given page the script is running on. When you insert a value into document.cookie, a cookie will be created. The syntax is identical to that of the HTTP header: document.cookie="foo=bar; path=/; expires=Mon, 01-Jan-2001 00:00:00 GMT";

4.2 Creating cookies with JavaScript This function requires that a name and a value are passed, with all other parameters optional. function setCookie (name, value, expires, path, domain, secure) { document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } Usage: setCookie("foo", "bar", "Mon, 01-Jan-2001 00:00:00 GMT", "/");

5.2 Retrieving cookies with JavaScript To retrieve cookies with JavaScript, use document.cookie again. Typically, document.cookie has a string like so: foo=bar;this=that;somename=somevalue;..... This string contains every name-value pair valid for this document, separated by semicolons. This can make searching for your needed value a bit of a pain. The getCookie() function does make this simpler: function getCookie(name) { var cookie = " " + document.cookie; var search = " " + name + "="; var setStr = null; var offset = 0; var end = 0; if (cookie.length > 0) { offset = cookie.indexOf(search); if (offset != -1) { offset += search.length; end = cookie.indexOf(";", offset) if (end == -1) { end = cookie.length; } setStr = unescape(cookie.substring(offset, end)); } } return(setStr); } Usage: myVar = GetCookie("foo"); Here, myVar would equal bar.