11 1 Cookies CGI/Perl Programming By Diane Zak. 11 2 Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.

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.
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?
Website Development Registering Users – Introducing Cookies.
Python and Web Programming
XP Tutorial 9 New Perspectives on JavaScript, Comprehensive1 Working with Cookies Managing Data in a Web Site Using JavaScript Cookies.
Cookies & file i/o in perl. Survey (html form in notes)
Chapter 10 Managing State Information PHP Programming with MySQL.
Chapter 10 Maintaining State Information Using Cookies.
Objectives Learn about state information
OS and Application Files BACS 371 Computer Forensics.
 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.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
ITIS 1210 Introduction to Web-Based Information Systems Chapter 48 How Internet Sites Can Invade Your Privacy.
Practical PHP IDIA Spring 2012 Bridget M. Blodgett.
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.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
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.
2 1 Sending Data Using a Hyperlink CGI/Perl Programming By Diane Zak.
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.
Building PERL Scripts on a Windows system* *and running those scripts on an Apache server!
Chapter 8 Cookies And Security JavaScript, Third Edition.
12 1 Redirection CGI/Perl Programming By Diane Zak.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
COOKIES. INTERNET COOKIES What are they Where are they found What should you do about them.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
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
STATE MANAGEMENT.  Web Applications are based on stateless HTTP protocol which does not retain any information about user requests  The concept of state.
PHP Programming with MySQL Slide 10-1 CHAPTER 10 Managing State Information.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Introduction to Programming the WWW I CMSC Winter 2003.
5 1 Data Files CGI/Perl Programming By Diane Zak.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
10 1 Hidden Fields and CGI/Perl Programming By Diane Zak.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 State and Session Management HTTP is a stateless protocol – it has no memory of prior connections and cannot distinguish one request from another. The.
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.
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.
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.
COOKIES Gloria Soria Network Security COSC 356. What is a Cookie? A cookie is a piece of text that a Web Server can store on a user's hard disk. Cookies.
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.
CSE 154 Lecture 20: Cookies.
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.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
ITM 352 Cookies.
COOKIES.
Cookies and Sessions in PHP
Cookies and JavaScript
CGI II: Cookies & Stuff Web Programming.
CGI II: Cookies & Stuff Web Programming.
CGI II: Cookies & Stuff Web Programming.
CSc 337 Lecture 25: Cookies.
Presentation transcript:

11 1 Cookies CGI/Perl Programming By Diane Zak

11 2 Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies Create a cookie Send a cookie to a web browser Access the information stored in a cookie

11 3 Introduction Misconceptions about cookies: –Contain viruses –Gain access to private information stored on a computer Truth about cookies: –Cookie are just pieces of text Since they are not programs, they cannot pass a virus or read a hard disk

11 4 Introduction –Cookies only contain information that has been disclosed on the cookie’s website –A web site can only access information stored in its cookie Does not have access to any other site’s cookie files

11 5 Using a Cookie A cookie is a piece of data that a Web server stores in your computer –Stored in RAM Random Access Memory –Store on hard drive –Allows site to remember information about you Data entered on a form Number of times a site has been visited User preferences

11 6 Using a Cookie Every cookie can contain: –Required key and value –Optional information like expiration date 2 types of cookies: –Temporary cookie Also referred to as a session cookie Stored in RAM (Random Access Memory) Only exists while browser is open Erased from memory when the browser is closed

11 7 Using a Cookie 2 types of cookies: –Permanent cookie Stored in a text file Has expiration date telling browser when the cookie should be deleted Netscape stores in cookies.txt file –In Netscape directory Internet Explorer stores each cookie in a separate file –Each file name starts with your username –In Cookies directory

11 8 Using a Cookie Browser’s responsibilities: –Web browser keeps track of all cookies sent to it by a particular server –When a URL is typed into a browser, the browser searches RAM and the hard drive for any cookies belonging to the server Contacts server and transmits any cookies and the URL CGI.pm module contains functions for creating and retrieving cookies

11 9 Creating a Cookie cookie function: –Syntax: cookie (-name => key, -value => value, -path => path, -expires => expires); The => operator is the “corresponds to” operator. –Used to associate each argument with a value –Can use comma instead

11 10 Creating a Cookie PartsDescription key- Required - Name of value listed in –value - Can be string, number, scalar variable value- Required - Value of the cookie - Can be string, number, scalar variable, array, or hash path-Optional - Indicates the scripts to which the cookie will be sent - If omitted, sent to all scripts on server expires- Optional - When the cookie will expire - If omitted, will expire when the browser is closed

11 Creating a Cookie Expiration Settings: SettingCookie will expire +ns+nsin n seconds +nm+nmin n minutes +nh+nhin n hours +nd+ndin n days nowimmediately +nM+nMin n months +nY+nYin n years

11 12 Creating a Cookie

11 13 Sending a Cookie to the Browser header function: –Part of CGI.pm –Sends one or more cookies to a browser –The header function already sends the print “Content-type: text/html\n\n”; statement If it is typed into the script before the header function, the cookies will not be sent to the browser –Cookies must be sent before the Content-type header line is processed

11 14 Sending Cookies to a Browser

11 15 Accessing the Information Stored in a Cookie When a URL is entered into a browser: –Browser searches RAM and hard drive for cookies for that server –Browser contacts server and sends cookies, URL, and any form data –Server sends cookie and form data to script if the URL is associated with a script

11 16 Accessing the Information Stored in a Cookie Syntax: –cookie (key) Example: $color = cookie(‘Color’); print “ \n”; The value of the Color key is assigned to the $color variable –When the cookie was created, its name was “Color”, and its value will change the background color of a dynamic web page

11 17 Examples: $custid = cookie(‘Id’); print “Customer id: $custid = split (/ /, cookie(‘Record’)); foreach my $rec { print “$rec \n”; } If the value associated with the cookie’s key is an array: Use split to divide the value associated with the key Use the foreach loop to go print each element Accessing the Information Stored in a Cookie

11 18 The Jubilee Book Club Web Pages If the user has never visited the site, the Name text box should be blank If the user has visited the site, his/her name should appear in the Name text box

11 19 The Jubilee Book Club Web Pages

11 20 Planning and Coding the book2.cgi Script –Each time the user visits the web site, the book2.cgi script will create the Name cookie and send it to the user’s browser –It will overwrite the existing Name cookie (if any) –The cookie will expire in 6 months

11 21 Planning and Coding the book1.cgi Script

11 22 Planning and Coding the book1.cgi Script

11 23 Summary A cookie is a piece of data that a Web server can store on your computer (RAM, hard drive) depending on the life span of the cookie. A cookie cannot pass a virus or read a hard drive. A cookie can contain only as much information as you disclose on the web site that creates the cookie. Every cookie has a key and value and can contain optional information like path and expiration date.

11 24 Summary A temporary (session) cookie is stored in RAM and erased from memory when the browser is closed. A persistent cookie is stored in a text file on the hard drive. –Expiration date telling browser when to delete Like form data, cookies are sent with the requested URL. The cookie function, defined in CGI.pm, can create a cookie or access data stored in a cookie.

11 25 Summary cookie function: –must specify –name and –value functions. –The => operator is called the “corresponds to” operator. –The –path argument determines which scripts receive the cookie. –The –expires argument indicates the expiration period for the cookie. You can use the header function to send one or more cookies to a browser –Defined in cgi.pm –Sends cookie information and the Content-type header line to the browser Don’t need to type in the Content-type header line