Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Databases for Web Applications Courses example Persistent information. Cookies. Session Homework: Examine a computer (your own or in a lab) for.

Similar presentations


Presentation on theme: "Creating Databases for Web Applications Courses example Persistent information. Cookies. Session Homework: Examine a computer (your own or in a lab) for."— Presentation transcript:

1 Creating Databases for Web Applications Courses example Persistent information. Cookies. Session Homework: Examine a computer (your own or in a lab) for cookies and shared objects. Experiment with cookie programs. Read article.

2 Students/Courses/Faculty Database: Students Courses Teachers Also need course offerings Student taking a course

3 Write out examples Student ID, name, major, …. Id, Course name, description, credits… Id, Faculty name, rank, tenure, years,… Course offering: id, section, semester (time), teacher, location Student taking course: id, student ID, course offering id, audit or for credit

4 SQL List of all students taking a course taught by ‘Jeanine Meyer’ List of all students taking courses with teachers that are adjuncts ???

5 Note It is not essential that a question be answered totally by SQL (though it is very powerful). You/your php code can examine a result set.

6 Persistent data (aka state information) Data that lasts longer than one loading of an html page Store information on the server –File –Database Store information on the client computer –Cookie –Flash terminology: SharedObject Keep information for the session by sending and re-sending it with the HTTP headers –Php session construct

7 Cookies Meant to be disarming name Small file stored on client computer accessible by programs on the same domain (some limitations possible here), with some time limits –YOUR computer –PROMISE that these files don't do harm. There have been 'leaks' on IE Cookies can be set by program running on client (e.g., JavaScript) or server (e.g., php)

8 Marketing Cookies, web beacons, Flash SharedObjects are used frequently for marketing purposes. Homework: Cathy Dwyer article http://csis.pace.edu/~dwyer/research/AMC ISDwyer2009.pdf http://csis.pace.edu/~dwyer/research/AMC ISDwyer2009.pdf

9 Show cookies FireFox: Tools Options Privacy Show Cookies IE: Tools Internet Options General Settings (under Browsing history) View files ??? Laptop users: do this and next …

10 Flash player Settings manager for new sites –http://www.macromedia.com/support/docume ntation/en/flashplayer/help/settings_manager0 3.htmlhttp://www.macromedia.com/support/docume ntation/en/flashplayer/help/settings_manager0 3.html Settings for sites already visited (trust that list is complete?) –http://www.macromedia.com/support/docume ntation/en/flashplayer/help/settings_manager0 7.html#117717http://www.macromedia.com/support/docume ntation/en/flashplayer/help/settings_manager0 7.html#117717

11 Browser (user) limits Your user/customer/player/client may choose to forbid all cookies or Make decision case by case. Note: most people don't do this, but designers should make plans –Retain information some other way php session, store information on server, ? –Make user re-enter information Cookies are browser specific. If you visit a site using IE and set cookies and then Firefox, it won't pick up the cookie

12 Setting and using cookies Required –Name –Value Optional –expires. Time from a base time. JavaScript uses milliseconds. PHP uses seconds! Default is the end of the browser session –path. Default is path of calling document Would allow other scripts in the document directory. If you want to restrict it further, put in more information: "/~Jeanine/db/" –domain. Default is domain of this document By setting domain to purchase.edu, I can allow scripts from newmedia.purchase.edu AND www.purchase.edu, etc. –secure. True requires secure transmission

13 Javascript document.cookie = mycookie; Where mycookie is a string like a query string, consisting of cookiename=cookievalue; path=…; domain=…; secure=…. NOTE: cookiename and cookievalue are your name and value.

14 JavaScript example http://newmedia.purchase.edu/~Jeanine/cookie.ht ml Examine source code The setcookie and getcookie functions are much more general than needed. Code uses the conditional operator and also the construct (expires). Does this value exist (is it set)? Expiration is a year from now –365 * 24 * 60* 60* 1000 milliseconds

15 PHP cookies setcookie(name, value, expires,path,domain,secure); where the last 4 are optional NOTE: actually, the last 5 are optional. To delete a cookie with the name blah setcookie(blah); CAUTION: setcookie must occur before any HTML produced (print, echo). –Watch out for blank lines!

16 cookies.php No expiration time set. Expires when browser is closed. One file: form and handler of form Outline If form submitted Set cookie Welcome message Else get cookies already set (if they exist) display form

17 <?php $submitted=$_POST['submitted']; if (@($submitted)) { $cname=$_POST['cname']; $type=$_POST['type']; setcookie("ccname",$cname); setcookie("ctype",$type); ?> Use cookie Welcome <? print ("$cname! \n"); print (" You like $type cookies."); ?> <? }

18 else { $ccname=$_COOKIE['ccname']; $ctype=$_COOKIE['ctype']; ?> Form for cookies Your name <input type=text name='cname' value=' '> Your favorite cookie <input type=text name='type' value=' '>

19 cookies5min.php Note: the cookies.php cookies may expire quicker or longer than this one. If you use both, what happens??? Expiration is given in SECONDS!!!! This code also prints out the time in milliseconds, just for fun. setcookie("ccname",$cname,time()+5*60); setcookie("ctype",$type, time()+5*60);

20 Homework Write (set) and read cookies! Read Cathy Dwyer article –Use tools to examine cookies on your own computer –Prepare to discuss Keep working on enhancements to basic projects –Come to class prepared to say what enhancement(s) you are doing.


Download ppt "Creating Databases for Web Applications Courses example Persistent information. Cookies. Session Homework: Examine a computer (your own or in a lab) for."

Similar presentations


Ads by Google