CS50 SECTION WEEK 8 Kenny Yu. Announcements  Problem Set 5 Returned.  Problem Set 7 Walkthrough up  Final Project’s Pre-proposal due 11am Monday 11/9.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

HyperText Markup Language (HTML). Introduction to HTML Hyper Text Markup Language HTML Example The structure of an HTML document Agenda.
George Mason University
Understand Web Page Development Software Development Fundamentals LESSON 4.1.
Kyung Hee University 1 1 Application Layer. 2 Kyung Hee University Position of Application Layer.
1 HTML Markup language – coded text is converted into formatted text by a web browser. Big chart on pg. 16—39. Tags usually come in pairs like – data Some.
Introduction to Web Database Processing
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.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Chapter 2 Introduction to HTML5 Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Web Programming Language Dr. Ken Cosh Week 1 (Introduction)
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
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.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
INTRODUCTION TO WEB DATABASE PROGRAMMING
IT 210 The Internet & World Wide Web introduction.
Computer Concepts 2014 Chapter 7 The Web and .
CS 299 – Web Programming and Design CS299: Web Programming and Design Instructor: Dr. Fang (Daisy) Tang.
1 Homework / Exam Exam 3 –Solutions Posted –Questions? HW8 due next class Final Exam –See posted schedule Websites on UNIX systems Course Evaluations.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
Creating a Basic Web Page
Copyright © cs-tutorial.com. Introduction to Web Development In 1990 and 1991,Tim Berners-Lee created the World Wide Web at the European Laboratory for.
Chapter 1: Introduction to Web
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
Server-side Scripting Powering the webs favourite services.
With your friendly Web Developer, Chris.. Terminology  HTML - > Hypertext Markup Language  CSS -> Cascading Style Sheet  open tag  close tag  HTTP->Hypertext.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
CS134 Web Design & Development Introduction to the Internet Mehmud Abliz.
2013Dr. Ali Rodan 1 Handout 1 Fundamentals of the Internet.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Website Development & Management Creating Web Pages CIT Fall Instructor: John Seydel, Ph.D.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
HTML. Principle of Programming  Interface with PC 2 English Japanese Chinese Machine Code Compiler / Interpreter C++ Perl Assembler Machine Code.
NMD202 Web Scripting Week3. What we will cover today Includes Exercises PHP Forms Exercises Server side validation Exercises.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences Chapter.
1 Welcome to CSC 301 Web Programming Charles Frank.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Web Design (1) Terminology. Coding ‘languages’ (1) HTML - Hypertext Markup Language - describes the content of a web page CSS - Cascading Style Sheets.
CSC3530 Software Technology Tutorial One Assignment overview & HTML basics.
HOW THE WEB WORKS Reference: Learning Web Design (4 th edition) by Robbins 2012 – Chapter 2 (pp. 21 – 32)
1 Web Servers (Chapter 21 – Pages( ) Outline 21.1 Introduction 21.2 HTTP Request Types 21.3 System Architecture.
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.
CS 330 Class 2: Programming Plan for Today Recap from last time More UNIX Begin HTML (material from Chapters 5-8) –Tags and attributes –Hyperlinks Features.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
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.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Web Design Terminology Unit 2 STEM. 1. Accessibility – a web page or site that address the users limitations or disabilities 2. Active server page (ASP)
IN THIS LESSON WE WILL REVIEW THE STRUCTURE OF THE INTERNET AND HOW BROWSERS ASSEMBLE WEBSITES BASED ON INSTRUCTIONS THEY RECEIVE FROM SERVERS. Internet.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
HTML III (Forms) Robin Burke ECT 270. Outline Where we are in this class Web applications HTML Forms Break Forms lab.
National College of Science & Information Technology.
Internet and World Wide Web Introduction to the Internet.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Web Development. Agenda Web History Network Architecture Types of Server The languages of the web Protocols API 2.
CISC103 Web Development Basics: Web site:
Chapter 27 WWW and HTTP.
Introduction to World Wide Web
Presentation transcript:

CS50 SECTION WEEK 8 Kenny Yu

Announcements  Problem Set 5 Returned.  Problem Set 7 Walkthrough up  Final Project’s Pre-proposal due 11am Monday 11/9  My section resources are posted here: 

Agenda  Chmod  Overview of the Internet  Client-Server Model  HTML  Tags, attributes  doctype  CSS  Style attribute, selectors, external stylesheet  PHP  Handling GET and POST  MySQL  SELECT, INSERT, UPDATE, DELETE  phpmyadmin

Chmod  Allows you to restrict read, write, and execute permissions on your files and directories accessible over Internet/other users on the computer  This is how I hide solutions to labs!  Permissions assigned by setting three octal values which correspond to permissions to ‘read’, ‘write’ or ‘execute’  3 groups correspond to User, Group, World

Chmod jharvard ~/tempdir$ ls –l total jharvard jharvard Oct 31 00:18 example.c 1 jharvard jharvard Oct 31 00:18 a.out a.out: User: rwx => 111 => 7 (octal) Group: r-x => 101 => 5 (octal) World: r-x => 101 => 5 (octal)

Chmod  Can use octal values directly  chmod 644 main.c example.c  Sets permissions to read and write for user, read permissions for everyone else  Or use shorthand  chmod u+x main.c example.c Gives executable permissions for user. The first character can be also “g” (group), “o” (other), “a” (all); the “+” can be a “-” for removing permissions; final letter can be “x”, “r”, “w” See man page for more details!

Chmod  For your appliance  You should chmod 755 for directories, especially ~/public_html and ~  chmod 755 for PHP files  chmod 644 for all other files (CSS, JavaScript, Images)

Overview of the Internet

 Simply put, the Internet is a network of networks  All computers on the same network can communicate with each other using established conventions:  TCP (Transmission Control Protocol): convention computers use to transfer data (in “packets”) with one another (analogy: the letter you send via mail)  IP (Internet Protocol): convention computers use to route packets from one computer to another (analogy: the US Postal System) every computer has an I.P. Address unique to that computer (e.g. your home address) IPv4: ###.###.###.### where # is 0-9 IPv6: ####:####:####:####:####:####:####:#### where # are hexademical digits  DNS (Domain Name System): allows us to alias IP addresses with readable names (analogy: the Quad = 59 Shepard Street [not actually true]) E.g. google.com =  HTTP (Hypertext Transfer Protocol) – the world wide web protocol  What we refer to as the “worldwide web” (HTTP) is only a subset of what we can do with the internet!  ssh, Skype, (SMTP), instant messaging, more!

Server-Client Model  On your browser (the client), whenever you go to you send an HTTP request that is either GET or POST to the IP address that the DNS resolves towww.google.com  GET generally to retrieve data  POST generally to store data  Your HTTP request gets relayed by routers until it hits Google’s servers.  A server is a computer that simply listens to requests (could be HTTP, could be other kinds) and serves the appropriate data or files.  Google’s servers run programs that will handle the request appropriately and send an HTTP response back to you in the form of an HTML document.  Your browser renders the HTML document appropriately  It also sends HTTP requests to retrieve any included images, CSS files, JavaScript files, etc.

Server-Client Model Client (JavaScript handles all the logic on the client-side, HTML renders the page, CSS adds style) Client (JavaScript handles all the logic on the client-side, HTML renders the page, CSS adds style) Server (PHP, Python, Ruby, Java, etc. handle the logic on the server-side) Server (PHP, Python, Ruby, Java, etc. handle the logic on the server-side) Database (SQL) Database (SQL) HTTP GET/POSTFetch data from database Retrieved data from databaseSend HTML response

Agenda  Chmod  Overview of the Internet  Client-Server Model  HTML  Tags, attributes  doctype  CSS  Style attribute, selectors, external stylesheet  PHP  Handling GET and POST  MySQL  SELECT, INSERT, UPDATE, DELETE  phpmyadmin

HTML  HyperText Markup Language  Used to format the structure of web pages.  NOT a programming language

Why HTML?  Let’s say I wanted to organize all the Pokemon in a machine-human-readable format. We can organize it with a markup language like this: Bulbasaur Leaf 12 vine whip solar beam razor leaf Charmander...

HTML  In the same way, we markup the contents of a webpage with HTML to give the content structure:

HTML  Tags enclose regions of a page  E.g.,,,  Most beginning tags have ending tags (exceptions include and tags)  In general, close most recently opened first  a paragraph!  Tags may have attributes, which are like parameters for a tag—need quotes around the value!  Stuff

HTML specifies which HTML convention, here we use HTML5 the html of a webpage is split into head and body head typically contains metadata and references to external stylesheets and javascript files Welcome! body typically contains the structure and content “divider” tag Hello World! “paragraph” tag

HTML – Useful tags   Anchor tags—provides a link to another page ,, …  Header tags, used to emphasize different text  unordered list  ordered list  list item  E.g. foo bar  forms, look up the possible options!

HTML Resources   Provides documentation and tutorials on HTML, JavaScript, CSS, PHP, SQL, and other Internet- related thingies.  Learn to look up documentation!  For this class, you can use any version of HTML or XHTML as long as it validates on  HTML5 ( ) is recommended because it is becoming the new standard.

Agenda  Chmod  Overview of the Internet  Client-Server Model  HTML  Tags, attributes  doctype  CSS  Style attribute, selectors, external stylesheet  PHP  Handling GET and POST  MySQL  SELECT, INSERT, UPDATE, DELETE  phpmyadmin

?  Sure, we have the structure of a web page, but what makes it look funky and pretty? How do we stylize it?

CSS  CSS – Cascading Style Sheets  Allows us to create style sheets which describe how different types of tags and elements of tags should be rendered to the user  Makes things look pretty!  May be inlined into the HTML using the “style” tag or included in a separate file

CSS - Inlining  Examples:  align: center;  font-size: 10px;  color: #F8C67D;  display: block;  This is centered with small font.

CSS – External File styles.css: p { align:center; } h1, h2 { font: 20px; color: blue; } index.html: This will be centered This will be blue

CSS - Selectors  In general, a CSS block looks like: selector { attribute: value; } Selectors can be lists of selectors  Ids (exactly one on a page): #myspecialparagraph  Classes (multiple on a page):.myspecialdivs

CSS-Selectors … Hi! just another lame paragraph

Agenda  Chmod  Overview of the Internet  Client-Server Model  HTML  Tags, attributes  doctype  CSS  Style attribute, selectors, external stylesheet  PHP  Handling GET and POST  MySQL  SELECT, INSERT, UPDATE, DELETE  phpmyadmin

?  Now that we have rendering the HTML and CSS down, how did the server generate the HTML in the first place?

PHP: PHP Hypertext Processor  When accessed, PHP dynamically generates a webpage which it then outputs to the browser  PHP code is executed by the server, not by the browser  Next week, you’ll see JavaScript, which is executed by the client (your browser)  PHP code is enclosed in tags  All PHP variables are prefaces by $  You do NOT declare variables with a type!

PHP C CompiledInterpreted Statically TypedDynamically Typed - Compiled on gcc, then run executable - Each variable is declared with a type at compile time. You cannot (without casting) mix and match data types: int a = 3; char *s = “hello”; s = a; // compiler will produce a warning - Doesn’t get compiled; whole program generally interpreted line by line – really slow compared to C! - Variables don’t have types (actually, types Figured out at runtime) You can do weird mixings of types: $a = 3; $s = “hello”; $s = $s. $a; // “hello3”

PHP GET and POST  Client can send parameters GET and POST requests to the server  GET (bookmarkable) – the parameters are in the URL Parameters start after ?, name=value, separated by &  POST – used for sending larger data or secure data Files Passwords, credit card numbers

PHP  Special variables $_GET and $_POST which are associative arrays (dictionaries!)  Map the parameter name to the parameter value  $name = $_GET[“name”];  $password = $_POST[“pswd”];  Must check if these fields are set first!  if (!empty($_POST[“name”]) { if not empty…}

PHP . string concatenation  $s = “hello”. “apple”; ==> “helloapple”  $s = “hello”. 4; ==> “hello4”  == equality, after type juggling  4 == “4” ==> true  === equality, and if they are of the same type  4 === 4 ==> true  4 === “4” ==> false

PHP  Overall flow 1. You fill out a form on index.html 2. The form submits the data via POST or GET to magic.php 3. magic.php handles the POST and GET parameters appropriately and generates the HTML page 4. The response is sent back to your browser.

Agenda  Chmod  Overview of the Internet  Client-Server Model  HTML  Tags, attributes  doctype  CSS  Style attribute, selectors, external stylesheet  PHP  Handling GET and POST  MySQL  SELECT, INSERT, UPDATE, DELETE

?  Okay, so the server generates HTML and all that jazz. But how does it keep track of all the data I send it? How does Google remember my s?

MySQL  SQL – Structured Query Language  MySQL is a database software that allows us to efficiently store a collection of data as entries containing a set of distinct fields containing values  Use SQL to interact with the software  Databases contain tables, which contain rows, which contain fields  Note: MySQL is just one of many open source database software options. Google actually uses their own system called BigTable.

MySQL Queries  INSERT : inserts a new entry  INSERT INTO students (name, id) VALUES (‘Kenny’, 5);  DELETE : removes an existing entry  DELETE FROM students WHERE id = 5;  SELECT : select one or more entries  SELECT * FROM students WHERE name = ‘Kenny’  UPDATE : update the fields of an existing entry  UPDATE students SET name = ‘LENNY’ WHERE id = 5;

MySQL – students example idnameyearhouse 0Kenny2014Quincy House 1John1636Crimson Yard

MySQL – students example INSERT INTO students (id, name, year, house) VALUES (2, ‘Kenny’, 1999, ‘Eliot House’); idnameyearhouse 0Kenny2014Quincy House 1John1636Crimson Yard 2Kenny1999Eliot House

MySQL – students example SELECT * FROM students; -> returns all fields of all rows SELECT name FROM students WHERE id >= 1; -> returns John and Kenny SELECT id, year FROM students WHERE name = ‘Kenny’; -> returns (0,2014) and (2,1999) idnameyearhouse 0Kenny2014Quincy House 1John1636Crimson Yard 2Kenny1999Eliot House

MySQL – students example DELETE FROM students WHERE name = ‘John’; idnameyearhouse 0Kenny2014Quincy House 1John1636Crimson Yard 2Kenny1999Eliot House

MySQL – students example UPDATE students SET name = ‘Lenny’ WHERE name = ‘Kenny’; idnameyearhouse 0Kenny Lenny2014Quincy House 2Kenny Lenny1999Eliot House

mysql_real_escape_string  Always assume the user input is malignant  What if for the name field, someone wrote as a name: ‘); DROP students; SQL injection attack!  Use mysql_real_escape_string to escape user input

Agenda  Chmod  Overview of the Internet  Client-Server Model  HTML  Tags, attributes  doctype  CSS  Style attribute, selectors, external stylesheet  PHP  Handling GET and POST  MySQL  SELECT, INSERT, UPDATE, DELETE

HTML, CSS, PHP, (JavaScript)?!!?  This is a lot of languages to learn in a very little amount of time  Don’t worry, most people don’t memorize, they just read the documentation  Or do a google search (other people probably have the same problem as you)  Resources   

The web is such a friggin’ hack “Imagine if I told you we were going to build a system to run our company. We’d use a domain specific language for the data- store, a second language for the back-end code which is run on a server written in a third language, a fourth xml-based approach to explain the documents, a fifth DSL to explain the styling of said document, a sixth language to write the front- end code, and a seventh “language” that is actually a library that makes the sixth language usable for our purposes. Would anyone think I was crazy?”

The web is such a friggin’ hack “Imagine if I told you we were going to build a system to run our company. We’d use a domain specific language for the data- store, a second language for the back-end code which is run on a server written in a third language, a fourth xml-based approach to explain the documents, a fifth DSL to explain the styling of said document, a sixth language to write the front- end code, and a seventh “language” that is actually a library that makes the sixth language usable for our purposes. Would anyone think I was crazy?” You will know what all of these are by the end of this class! SQL, PHP (and other languages as well), C (Unix Operating Systems), HTML, CSS, JavaScript, jQuery (not part of this course)

Fun Fun Fun  More pokemon!  Grab source code here:  Working example here: