INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
Lecture 14 HTML Forms CPE 401 / 601 Computer Network Systems slides are modified from Dave Hollinger.
CIS101 Introduction to Computing Week 08. Agenda Your questions JavaScript text Resume project HTML Project Six This week online Next class.
CPSC 203 Introduction to Computers Tutorial 59 & 64 By Jie (Jeff) Gao.
How the web works: HTTP and CGI explained
World Wide Web1 Applications World Wide Web. 2 Introduction What is hypertext model? Use of hypertext in World Wide Web (WWW) – HTML. WWW client-server.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
CGI Common Gateway Interface. CGI is the scheme to interface other programs to the Web Server.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
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)
INTERNET APPLICATION DEVELOPMENT For More visit:
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
1 Session 1: Introduction to HTML Spring Today’s Agenda Cover useful terminology for today’s session HTML, browsers, servers, etc. HTML Tags Get.
CP476 Internet Computing CGI1 CGI is a common way to provide for specific computations on server side, interactions with users, or access to databases.
CSU - DCE Advanced Perl CGI Operation - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) on the.
CPSC 203 Introduction to Computers Lab 23 By Jie Gao.
JavaScript – Quiz #9 Lecture Code:
LOGO FORMs in HTML CHAPTER 5 Eastern Mediterranean University School of Computing and Technology Department of Information Technology ITEC229 Client-Side.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
ITCS373: Internet Technology Lecture 5: More HTML.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
CSU - DEO Introduction to CGI - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to the Common Gateway Interface (CGI) Instructor: Joseph DiVerdi,
CSE 341, S. Tanimoto Lisp CGI - 1 Lisp CGI Programming for the Web Web servers can invoke Lisp to “intelligently” create web pages on the fly. We will.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
ECMM6018 Enterprise Networking for Electronic Commerce Tutorial 7
Creating a Remotely-Hosted Web Site Fort Collins, CO Copyright © XTR Systems, LLC Creating Your First Remotely-Hosted Web Site Instructor: Joseph DiVerdi,
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
Copyright 2007 Byrne Reese. Distributed under Creative Commons, share and share alike with attribution. Intermediate Perl Programming Class Three Instructor:
Netprog CGI and Forms1 CGI and Forms A detailed look at HTML forms.
Week 10: HTML Forms HNDIT11062 – Web Development.
5 th ed: Chapter 17 4 th ed: Chapter 21
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.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
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,
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
SlideSet #20: Input Validation and Cross-site Scripting Attacks (XSS) SY306 Web and Databases for Cyber Operations.
Simple PHP Web Applications Server Environment
Basic Web Design UVICELL Week 4 Templates and site management Week 4 Templates and site management.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
CCT396, Fall 2011 Database Design and Implementation Yuri Takhteyev University of Toronto This presentation is licensed under Creative Commons Attribution.
National College of Science & Information Technology.
INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
CCT395, Week 7 SQL with PHP This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit
Introduction to Information Security
Review Databases and Objects
Special Topics in CCIT: Databases
Example of a table. Note that I looked at an example under CIS44.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
CGI I: Basics Web Programming.
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 ©
Hypertext Transport Protocol
Introduction to Programming the WWW I
Database Design and Implementation
Getting web pages First we need to get the webpage by issuing a HTTP request. The best option for this is the requests library that comes with Anaconda:
Data Modeling and Database Design
HTML: Basic Tags & Form Tags
Chapter 27 WWW and HTTP.
CGI I: Basics Web Programming.
HTML: Basic Tags & Form Tags
Presentation transcript:

INF1343, Winter 2012 Data Modeling and Database Design Yuri Takhteyev Faculty of Information University of Toronto This presentation is licensed under Creative Commons Attribution License, v To view a copy of this license, visit This presentation incorporates images from the Crystal Clear icon collection by Everaldo Coelho, available under LGPL from

Week 8 Building Database-Driven Web Applications

Interactivity template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" name = raw_input("What is your name? ") query = fill_template(query_template, name) execute_query(query) for row in fetch_all_rows(): world = get_row_value(row, "homeworld") if world==None: print greeting + name else: print fill_template(template, name, world) (We stopped here in class.)

Or Rather template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" name = raw_input("What is your name? ") query = fill_template(query_template, name) execute_query(query) if get_row_count() > 0 : rows = fetch_all_rows() row = rows[0] world = get_row_value(row, "homeworld") if world==None: print greeting + name else: print fill_template(template, name, world) else : print "No such user!"

Worlds as Passwords template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" name = raw_input("What is your name? ") world = raw_input("Where are you from? ") query = fill_template(query_template, name) execute_query(query) if get_row_count() > 0 : rows = fetch_all_rows() row = rows[0] real_world = get_row_value(row, "homeworld") if world==real_world: print fill_template(template, name, world) else: print "Access denied!" else : print "No such user!"

Worlds as Passwords template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s";""" name = raw_input("What is your name? ") world = raw_input("Where are you from? ") query = fill_template(query_template, name) execute_query(query) if get_row_count() > 0 : rows = fetch_all_rows() row = rows[0] real_world = get_row_value(row, "homeworld") if world==real_world: print fill_template(template, name, world) else : print "Access denied!"

Worlds as Passwords template = "Greetings, %s from %s!" query_template = """select * from persona where name="%s" and world="%s";""" name = raw_input("What is your name? ") world = raw_input("Where are you from? ") query = fill_template(query_template, name, world) execute_query(query) if get_row_count() > 0 : print fill_template(template, name, world) else : print "Access denied!"

What about Inserts? from padawan import * connect_to_db("okenobi", "okenobi") query_template = """insert into persona(name) values ("%s");""" name = raw_input("What is your name? ") query = fill_template(query_template, name) execute_query(query) print "You are now in our database!"

‘%’ in Queries from padawan import * connect_to_db("okenobi", "okenobi") query_template = """select * from persona where name like "%%s%";""" name = raw_input("What is your name? ") query = fill_template(query_template, name) print query Use % in the template when you want to have % in the query: like "%%s%" → like "%Bob%"

“r2”, “alice”, “pumpkins” “alice”, “pumpkins” Telnet (1969) ok “python greetings.py” “What is your name?”

“r2”, “alice”, “pumpkins” “alice”, “pumpkins” FTP (1971) ok “ftp>” “get /path/to/ewoks.txt” ewoks.txt the file is saved locally

“r2”, “/path/to/ewoks.txt” “get /path/to/ewoks.txt” Anonymous FTP ewoks.txt the file is saved locally ftp://yoda/path/to/ewoks.tx t

“r2”, “/path/to/ewoks.html” “GET /path/to/ewoks.html” HTTP (1991) the content of ewoks.html l ewoks.html is displayed

HTML Ewoks The List of Ewoks... See:

Basic Web Setup 1.Create an HTML file. Call it “test.html”. 2.Put it in ~/public_html. Use an SCP client. ~ = your home directory. 3.Set permissions. Make the file readable by “other”. 4.Access it in the browser. (Replace “okenobi” with your username.)

Generated HTML from padawan import * connect_to_db("starwars", "okenobi") query = "select * from persona" execute_query(query) html_template = """ %s is from %s """ for row in fetch_all_rows(): name = get_row_value(row, "name") world = get_row_value(row, "homeworld") if world!=None: print fill_template(html_template, name, world)

Run with Redirection python personas.py > ~/public_html/personas.html (You can use WinSCP to check that the file ended up in the right place and that the permissions are correct.)

“r2”, “/path/to/ewoks.py” “GET /path/to/ewoks.cgi” CGI the html output of ewoks.py ewoks.py contains code, but returns HTML html output is displayed

personas.py protocol server address path user name

personas.py #!/usr/bin/python print "Content-Type: text/html" print print " Personas " Again, create locally, copy to r2 with WinSCP. The file should be in ~/public_html/dynamic. Set permissions to allow “other” and “group” to read and execute but not to write.

CGI with Padawan #!/usr/bin/padawan print "Content-Type: text/html; encoding=utf8" print connect_to_db("starwars", "okenobi") query = "select * from persona" execute_query(query) html_template = """ %s is from %s """ for row in fetch_all_rows(): name = get_row_value(row, "name") world = get_row_value(row, "homeworld") if world!=None: print fill_template(html_template, name, world)

Passing Parameters Option 1, “GET” (in the URL) Option 2, “POST” (invisibly) (we'll get back to this)

Accessing Parameters print_form() if form_has_field("species") : print "Species is defined!" else : print "Species is not defined. :(" s = get_form_field_value("species") print "The species is " + s

The Wrong Way template = """ select * from persona where species='%s'; """ if form_has_field("species") : s = get_form_field_value("species") query = fill_template(template, s) print query execute_query(query); count = get_row_count() print "Got ", count, "results!" Wrong!!!

Here Is Why /dynamic/personas.py?species=Human '%3Binsert+into+persona+(name,spec ies)+values+('X','Human')%3Bselect+ *+from+persona+where+'

Right template = """ select * from persona where species='%s'; """ if form_has_field("species") : s = get_form_field_value("species") safe_s = escape_string(s) query = fill_template(template, safe_s) print query execute_query(query); count = get_row_count() print "Got ", count, "results!"

HTML Forms <form action="/~okenobi/dynamic/personas.py" method="get"> Please select a species:

HTML Forms <form action="/~okenobi/dynamic/personas.py" method="get"> Please select a species: Human Ewok Wookiee

HTML Forms: POST <form action="/~kenobio1/cgi-bin/personas3.cgi" method="post"> Please select a species: Human Ewok Wookiee

initial request (a URL) an HTML page with a form a new request (another URL) an HTML page with a form a request with parameters an HTML page with hidden form elements a request with parameters an HTML page with hidden form elements

Prefilled Forms Please select a species: <input type="text" name="species" value="Human"/>

Hidden Elements Please select a species: <input type="hidden" name="species" value="Human"/>

Or Just in Links Click here for the Humans

Session Management “Cookies” Longer term storage in the browser Parameters Short-term, simpler conceptually

Questions?