Creating Databases for Web Applications cookie examples lab time: favorites cookies & Sessions class time for group work/questions on projects Next class:

Slides:



Advertisements
Similar presentations
LIS651 lecture 3 taming PHP Thomas Krichel
Advertisements

LIS651 lecture 3 functions & sessions Thomas Krichel
CookiesPHPMay-2007 : [‹#›] Maintaining State in PHP Part I - Cookies.
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.
Creating Databases for Web Applications Courses example Persistent information. Cookies. Session Homework: Examine a computer (your own or in a lab) for.
6/10/2015Cookies1 What are Cookies? 6/10/2015Cookies2 How did they do that?
Website Development Registering Users – Introducing Cookies.
©2009 Justin C. Klein Keane PHP Code Auditing Session 7 Sessions and Cookies Justin C. Klein Keane
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.
Using Session Control in PHP tMyn1 Using Session Control in PHP HTTP is a stateless protocol, which means that the protocol has no built-in way of maintaining.
CSE 154 LECTURE 13: SESSIONS. Expiration / persistent cookies setcookie("name", "value", expiration); PHP $expireTime = time() + 60*60*24*7; # 1 week.
Mark Dixon, SoCCE SOFT 131Page 1 19 – Web applications: Server-side code (ASP)
Chapter 10 Maintaining State Information Using Cookies.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
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.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
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 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.
Web Programming Language Week 7 Dr. Ken Cosh Security, Sessions & Cookies.
Chapter 8 Cookies And Security JavaScript, Third Edition.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Week seven CIT 354 Internet II. 2 Objectives Database_Driven User Authentication Using Cookies Session Basics Summary Homework and Project 2.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
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.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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.
Sessions in PHP – Page 1 of 13CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Sessions in PHP Reading: Williams.
Cookies and Sessions IDIA 618 Fall 2014 Bridget M. Blodgett.
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
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.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
How to maintain state in a stateless web Shirley Cohen
Sessions Brendan Knight A visitor accessing your web site is assigned a unique id. This id links to specific data that remains on the server. Sessions.
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.
Maintaining State in ASP. Problem - How do I maintain state information about the user  Several Methods –Cookies –Session variables –Hidden fields 
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.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
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.
HTTP Transactions 1. 2 Client-Server Model 3 HTTP HyperText Transport Protocol Native protocol for WWW Sits on top of internet’s TCP/IP protocol HTTP.
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
Cookies Tutorial Cavisson Systems Inc..
CSE 154 Lecture 20: Cookies.
CHAPTER 5 SERVER SIDE SCRIPTING
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 ©
Sessions and cookies (part 2)
Web Programming Language
Cookies and Sessions in PHP
Web Programming Language
Web Programming Language
Presentation transcript:

Creating Databases for Web Applications cookie examples lab time: favorites cookies & Sessions class time for group work/questions on projects Next class: presentations

cookies are entries into a file called cookies.txt on the client computer –can be placed there by client-side or server-side code. Server side code uses the HTTP header to set the cookie. used for things such as IDs and preferences. Used to compensate for HTTP being 'stateless' alternatives are storing information in –databases – so-called session variables held on the server (one per client) –the URL call (like method=get form data)

Samples php: set cookie, no expiration. This means cookie goes away when the browser is closed. php: set cookie, 5 minute expiration asp/JavaScript: set cookie, no expiration. asp/JavaScript: set cookie, 5 minute expiration

on sharon.ns.purchase.edu/jeanine cookie.php cookie5min.php cookie.asp cookie5min.php Question: does the cookie know if it is asp or php?

<?php if { setcookie("ccname",$cname); setcookie("ctype",$type); ?> Use cookie Welcome <? print ("$cname! \n"); print (" You like $type cookies."); ?> <? } before anything else sent to browser

else { ?> Form for cookies Your name <input type=text name='cname' value=' '> Your favorite cookie <input type=text name='type' value=' '>

<?php if { setcookie("ccname",$cname,time()+5*60); setcookie("ctype",$type, time()+5*60); ?> Use cookie Welcome <? print ("$cname! \n"); print (" You like $type cookies."); print(" The time in seconds is "); print(time()); ?> <? }

else { ?> Form for cookies Your name <input type=text name='cname' value=' '> Your favorite cookie <input type=text name='type' value=' '>

<% var submitted=String(Request.Form("submitted")); if (submitted !="undefined") { sname=String(Request("cname")); stype=String(Request("type")); Response.Cookies("ccname") = sname; Response.Cookies("ctype") = stype; %> Use cookie Welcome \n"); Response.Write (" You like "+ stype +" cookies."); %> <% }

else { %> Form for cookies Your name <input type=text name='cname' value=' <% fromcookiename=Request.Cookies("ccname"); Response.Write(fromcookiename);%> '> Your favorite cookie <input type=text name='type' value=' <% fromcookietype=Request.Cookies("ctype"); Response.Write(fromcookietype); %> '>

ASP The time expiration needs to be an asp datatype called variant. Need to convert the JavaScript date object to that type: var later=new Date(); //get now later.setMinutes(later.getMinutes()+5 ); // add 5 Response.Cookies("ccname").expires =later.getVarDate();

<% var submitted=String(Request.Form("submitted")); if (submitted !="undefined") { sname=String(Request("cname")); stype=String(Request("type")); var later=new Date(); //get now later.setMinutes(later.getMinutes()+5 ); // add 5 Response.Cookies("ccname") = sname; Response.Cookies("ccname").expires =later.getVarDate(); Response.Cookies("ctype") = stype; Response.Cookies("ctype").expires = later.getVarDate(); %> Use cookie Welcome \n"); Response.Write (" You like "+ stype +" cookies."); Response.Write(" Later is " + later); %> <% }

Form for cookies Your name <input type=text name='cname' value=' <% fromcookiename=Request.Cookies("currentclientname"); Response.Write(fromcookiename);%> '> Your favorite cookie <input type=text name='type' value=' <% fromcookietype=Request.Cookies("ctype"); Response.Write(fromcookietype); %> '>

Experiment do [one of the] cookies.php or cookies.asp go to another site, and go back to this script. exit the browser. try cookies5min exit the browser, but re-invoke browser and go the script. exit the browser and right 5 minutes and then re- invoke the browser and go to the script.

Explore Find the cookies.txt file on your lab computer and your home or office computer On my home computer, it was on c\Program Files\Netscape\users\jeanine

in the cookies.txt file sharon.ns.purchase.eduFALSE/ FALSE ctype chocolate+chip+ sharon.ns.purchase.eduFALSE/ FALSE currentclientname+Mommy

Cookies name & value –can also be a collection (complex cookie): name, keys and values Optionally, set –domain (purchase.edu would mean that sharon.ns.purchase.edu, rachel.ns.purchase.edu, etc. could use the cookie) –path (restriction to folders within domain) –secure: True or False (only set if browser using secure connection) Limits: each cookie <= 4kB (Netscape), number of cookies also limited (oldest deleted to make room for newest): limit sent per domain (20) and limit overall (300)

cookie parameters php –setcookie(string name, string value, int expire, string path, string domain, int secure) asp –Response.Cookies(name).Domain = domainstring –Response.Cookies(name).Path = pathString –Response.Cookies(name).Secure= True

deleting cookies set same name cookie to no value setcookie("cclient",""); –php: If you have specified a domain or path, you need to mention those attributes again in the setcookie call. Response.Cookies("cclient")=""; set same name cookie to have past expiration time setcookie("cclient","", time()-60); Response.Cookies("client").Expires="1/1/1980"

Caution Cookies are browser dependent –Look at the Cookies folder in Windows for the IE cookies Cookies are not dependent on asp or php: that is, –php reads cookies set by asp and –asp reads cookies set by php

Sessions A session is the time a client spends on a site. A session id is stored (as a cookie) on the client OR passed along via the URLs (using php only). The id is a key to session information stored on the server for each client. –Php sessions will work even if cookies have been disabled by the person using the browser Session information is stored on the server.

Sessions: php session_start(); called at each script using the session variables $total = …. $cart["pencils"] = $qty; $cart[$productname] = $productqty; session_register("total"); session_register("cart"); … in another script, can use $cart and $total. $result = session_is_registered("total"); session_unregister("total"); session_destroy();

Sessions: asp Session(sessionvariablename)= ….; = Session(sessionvariablename) Session(“cust_name”) = custname; Again, session variables can be scalar (simple) or complex, such as arrays or associative arrays (aka hashes or collections).

Authentication (briefly) Sessions In forms, use method= post & –'over the shoulder' security Re-direction: invoking another script must be before anything else sent to browser php: header("Location: otherpage.php"); exit; asp: Response.Redirect("otherpage.asp"); In re-direction and links, can add parameters: header("Location:page2.php?user=$username"); php: crypt(), md5() asp/JavaScript: use on-line sources. May need to code your own or purchase plugin.

Homework Keep working on enhancement projects –First presentation due class after break (3/23) Present requirements (yours and your 'system owner' and 'system user' –Final presentation (of enhanced projects) due following week (3/30) Your proposal for your own original project due week after. (4/6)