Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.

Slides:



Advertisements
Similar presentations
1. XP 2 * The Web is a collection of files that reside on computers, called Web servers. * Web servers are connected to each other through the Internet.
Advertisements

Copyright © 2003 Pearson Education, Inc. Slide 7-1 The Web Wizards Guide to PHP by David Lash.
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
How To Use OPAC.
CS 4720 RESTfulness CS 4720 – Web & Mobile Systems.
Social Web Design 1 Darby Chang Social Web Design.
Web Programming 1 Darby Chang Web Programming. Cookie 2 Web Programming.
Tables Tables provide a means of organising the layout of data
Social Web Design 1 Darby Chang Social Web Design.
Molecular Biomedical Informatics Web Programming 1.
Microsoft Office Illustrated Fundamentals Unit C: Getting Started with Unit C: Getting Started with Microsoft Office 2010 Microsoft Office 2010.
1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
CREATING A PAYMENT REQUEST FOR A NEW VENDOR
1 NewSouth HR Reporting Running the Leave Accruals Report.
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.
25 seconds left…...
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
Services Course Windows Live SkyDrive Participant Guide.
1 Creating a Data Backup Oakland University University Relations Updated - June 2006.
We will resume in: 25 Minutes.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
HTML Concepts and Techniques Fourth Edition Project 2 Creating and Editing a Web Page.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
Session Management A290/A590, Fall /25/2014.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1.
Social Web Design 社群網站設計 1 Darby Chang 張天豪 Social Web Design 社群網站設計.
 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.
Molecular Biomedical Informatics 分子生醫資訊實驗室 Social Web Design & Research 社群網站設計 & 研究 Social Web Design & Research 1.
Chapter 25 Utilizing Web Storage.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
JavaScript, Fourth Edition
CS453: State in Web Applications (Part 1) State in General Sessions (esp. in PHP) Prof. Tom Horton.
USING PERL FOR CGI PROGRAMMING
Feedback #2 (under assignments) Lecture Code:
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
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.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Saving State on the WWW. The Issue  Connections on the WWW are stateless  Every time a link is followed is like the first time to the server — it has.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Fall 2000C.Watters1 World Wide Web and E-Commerce Clients & Client Side Processing.
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
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.
(Some from Chapter 11.9 – “Web” 4 th edition and
Web Technologies Lecture 6 State preservation. Motivation How to keep user data while navigating on a website? – Authenticate only once – Store wish list.
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.
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.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Web Storage and Cookies Cookies, Local and Session Storage SoftUni Team Technical Trainers Software University
WWW and HTTP King Fahd University of Petroleum & Minerals
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.
HTML5 and Local Storage.
CSc 337 Lecture 27: Cookies.
CSc 337 Lecture 25: Cookies.
Presentation transcript:

Molecular Biomedical Informatics 分子生醫資訊實驗室 Web Programming 網際網路程式設計 1

Cookie 2 Web Programming 網際網路程式設計

The motivation HTTP is a stateless protocol, each subsequent click to a web site is treated as a new request by the web server Web developers have to put a lot of efforts for this Web Programming 網際網路程式設計 3

State using forms my $cgi = new CGI; my $state = $defined $cgi->param('state') ? $cgi->param('state')+1 : 0; print Next END Web Programming 網際網路程式設計 4 Use a parameter from HTML form to maintain state. If specified, operate accordingly; otherwise initialize. The parameter should match the term used in. Block output in Perl. Watch the label. Remember the empty line in between HTTP header and body. The actual HTML. In addition to show the state, we also need to send the state to the server. The hidden type is exactly for this purpose. Can we use get here?

The form solution Still has limitations and, more importantly, security issues Suppose that we use two tabs to open the same web site twice, we expect that the changes in the first tab should also be applied on the second tab, with a refresh at most –can you do this? Web Programming 網際網路程式設計 5

The cookie solution You need HTML form because you need to send users’ input to the server side and save them in either files or database Before this class, this is the only way to make users’ input permanent Cookie is another storage, on the client side Web Programming 網際網路程式設計 6

Cookie Conventionally, users aren’t comfortable if the web applications can save something on the client site, that is, your hard disk –HTML5 Web Storage –security issues Cookie, as a compromising way, is a limited storage –only 4 kb –cannot access cookies from other domains –cannot be programmed, cannot carry viruses, and cannot install malware on the host computer Web Programming 網際網路程式設計 7

Can you Web Programming 網際網路程式設計 8 figure out something evil to do to your classmates

Cookie is not 100% safe They can be used by spyware to track users’ activities –this does be a problem, think about Fabecook API –Facebook 新 Graph API 推出 – 你打算跟魔鬼做交易了 嗎?Facebook 新 Graph API 推出 – 你打算跟魔鬼做交易了 嗎? – 當 Facebook 統治了世界,你還有隱私可言嗎? 當 Facebook 統治了世界,你還有隱私可言嗎? –a major privacy concern that prompted European and US law makers to take action Cookies can also be stolen by hackers to gain access to a victim’s web account –bad habit breaks any security mechanism Web Programming 網際網路程式設計 9

State using cookie use CGI::Cookie; my $cgi = new CGI; my $state = defined $cgi->cookie('state') ? $cgi->cookie('state') : 1; 1 == $cgi->param('next') and ++$state and print "Set-Cookie: state=$state\n"; 1 == $cgi->param('clean') and $state = 1 and print "Set-Cookie: state=\n"; print Next Clean END Web Programming 網際網路程式設計 10 Include CGI::Cookie module and use cookie() instead param(). The cookie name should match the Set-Cookie filed of the HTTP header. The state is either from cookie or the initial value. param() is still useful for actions instead of states. Update cookie if required. Set cookie to a null string to clean it. Use two forms to reduce extra actions, such as a radio button. Remember that outputs before this empty line are HTTP header.

Is anything Web Programming 網際網路程式設計 11 wrong of the two-form solution

Cookie in JavaScript (jQuery) $(document).ready(function(){ $.cookie('state') && $('#state').text($.cookie('state')); $('#next').click(function(){ var state = $.cookie('state') ? parseInt($.cookie('state'))+1 : 2; $.cookie('state',state); $('#state').text(state); }); $('#clean').click(function(){ $.cookie('state',null); $('#state').text(1); }); }); The state is 1 Next Clean Web Programming 網際網路程式設計 12 Include jquery.cookie plugin and use $.cookie() to access cookie. It’s obvious that the code of the the JS version is longer (more things are done by yourself). The HTML. You need a place to show the state, but the code is usually more clear. Show state if existed. The initial value can be specified in HTML. Compared it to that specified in JS. When clicking next, change the state, save it and show it. Watch the parseInt() and the weird 2 here. When clicking clean, clean the cookie (by setting it to null) and show the initial state.

Is there Web Programming 網際網路程式設計 13 any benefits to develop an Ajax version?

14 I think you can figure out it by yourself :p Web Programming 網際網路程式設計

A review Workflow –use a tab to open a URL and change something –check the browser to see the cookie –use a second tab to open the same URL, see the changes and change something again –refresh the first tab  no longer stateless! Set-Cookie in HTTP header –HTTP cookieHTTP cookie –List of HTTP header fieldsList of HTTP header fields There is also a JavaScript (thus Ajax-able) version Web Programming 網際網路程式設計 15

Any Questions? Web Programming 網際網路程式設計 16 about cookie

HTML5 web storage 17 With HTML5, web pages can store data locally Web Programming 網際網路程式設計

HTML5 Web Storage Earlier, this was done with cookies More secure and faster –the data is not included with every server request, but used ONLY when asked for 5MB (vs. 4kb) Better JS integration Similarly, the data is stored in key/value pairs, and a web page can only access data stored by itself var state = localStorage.state || 1; localStorage.state = ++state; Web Programming 網際網路程式設計 18

Session 19 Web Programming 網際網路程式設計

When too many variables to store If you have two fields, you may use two cookie variables. But how about 100 fields? This is not ridiculous to, for example, a shopping car Cookie, web storage or even HTML form is technology while session is how to use these technologies It’s a concept (an application of above technologies) Web Programming 網際網路程式設計 20

Session Only one variable as an session ID, access the remaining data (include the state, which might be complex) with it –reduce the network traffic –make the data really permanent –more important, security CGI::Session using cookie CGI::Session How many issues are gone in web storage? var state = sessionStorage.state || 1; sessionStorage.state = ++state; –disappear after closing the browser Web Programming 網際網路程式設計 21

Any Questions? Web Programming 網際網路程式設計 22

Today’s assignment 今天的任務 Web Programming 網際網路程式設計 23

Enhance the user experience Make your web site state-sensitive. If you have no such a requirement, please add a “remember me” checkbox or remember the last parameters (such as search keywords) Reference –CGI::CookieCGI::Cookie –Cookie | jQuery PluginsCookie | jQuery Plugins –HTML5 Web StorageHTML5 Web Storage Your web site ( ex7) will be checked not before 23:59 11/19 (Tue). You may send a report (such as some important modifications) to me in case I did not notice your features. Or, even better, just explain your modifications in the homepage. Web Programming 網際網路程式設計 24