week8 Tommy MacWilliam week8 October 31, 2011

Similar documents
Introduction to WEB PROGRAMMING

Welcome Please sit on alternating rows. powered by lucid & no.dots.nl/student

recall: a Web page is a text document that contains additional formatting information in the HyperText Markup Language (HTML)

Which is why we ll now be learning how to write in CSS (or cascading sheet style)

CSC 121 Computers and Scientific Thinking

Html basics Course Outline

A Balanced Introduction to Computer Science, 3/E

Downloads: Google Chrome Browser (Free) - Adobe Brackets (Free) -

Hyper Text Markup Language HTML: A Tutorial

The internet is a worldwide collection of networks that link millions of computers. These links allow the computers to share and send data.

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

HTML + CSS. ScottyLabs WDW. Overview HTML Tags CSS Properties Resources

HTMLnotesS15.notebook. January 25, 2015

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 1

Programmazione Web a.a. 2017/2018 HTML5

Title: Jan 29 11:03 AM (1 of 23) Note that I have now added color and some alignment to the middle and to the right on this example.

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

CS 1100: Web Development: Client Side Coding / Fall 2016 Lab 2: More HTML and CSS

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

CSS.

Web Development and HTML. Shan-Hung Wu CS, NTHU

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar with Dynamic Background Image

Chapter 3 Style Sheets: CSS

CSS worksheet. JMC 105 Drake University

AP CS P. Unit 2. Introduction to HTML and CSS

Introduction to Multimedia. MMP100 Spring 2016 thiserichagan.com/mmp100

1/6/ :28 AM Approved New Course (First Version) CS 50A Course Outline as of Fall 2014

AOS Lab 4 HTML, CSS and Your Webpage

Building Your Website

quiz 1 details wed nov 17, 1pm see handout for locations covers weeks 0 through 10, emphasis on 7 onward closed book bring a , 2-sided cheat she

As we design and build out our HTML pages, there are some basics that we may follow for each page, site, and application.

Web Publishing Basics I

AOS 452 Lab 4: HTML, CSS and Your Webpage

3.1 Introduction. 3.2 Levels of Style Sheets. - The CSS1 specification was developed in There are three levels of style sheets

- The CSS1 specification was developed in CSS2 was released in CSS2.1 reflects browser implementations

CS 350 COMPUTER/HUMAN INTERACTION. Lecture 6

AGENDA. EMBEDDING FONTS [ Font Files & CSS font-family ] :: Online Font Converter :: ADD font-family css code to style.css

HTML and CSS: An Introduction

HTML & CSS November 19, 2014

epromo Guidelines DUE DATES NOT ALLOWED PLAIN TEXT VERSION

Chapter 1 Getting Started with HTML 5 1. Chapter 2 Introduction to New Elements in HTML 5 21

Web and Apps 1) HTML - CSS

HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

Table Basics. The structure of an table

CIS 228 (Fall, 2012) Exam 2, 11/20/12

Study Guide 2 - HTML and CSS - Chap. 6,8,10,11,12 Name - Alexia Bernardo

MPT Web Design. Week 1: Introduction to HTML and Web Design

Web Design 101. What is HTML? HTML Tags. Web Browsers. <!DOCTYPE html> <html> <body> <h1>my First Heading</h1> <p>my first paragraph.

COMS 359: Interactive Media

Part 3: Images & form styling NOMZAMO S WEBSITE

Web development using PHP & MySQL with HTML5, CSS, JavaScript

The Benefits of CSS. Less work: Change look of the whole site with one edit

1. Please, please, please look at the style sheets job aid that I sent to you some time ago in conjunction with this document.

COMP519 Web Programming Lecture 6: Cascading Style Sheets: Part 2 Handouts

HTML & CSS. Lesson 1: HTML Basics Lesson 2: Adding Tables Lesson 3: Intro to CSS Lesson 4: CSS in more detail Lesson 5: Review

c122jan2714.notebook January 27, 2014

introduction to XHTML

LING 408/508: Computational Techniques for Linguists. Lecture 14

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar

HTML and CSS COURSE SYLLABUS

Eng 110, Spring Week 03 Lab02- Dreamwaver Session

Block & Inline Elements

Introduction to HTML & CSS. Instructor: Beck Johnson Week 2

3.1 Introduction. 3.2 Levels of Style Sheets. - HTML is primarily concerned with content, rather than style. - There are three levels of style sheets

Introduction to using HTML to design webpages

11. HTML5 and Future Web Application

Taking Fireworks Template and Applying it to Dreamweaver

7300 Warden Avenue, Suite 503 Markham, Ontario Canada L3R 9Z6. Phone: Toll Free: Fax:

GIMP WEB 2.0 MENUS WEB 2.0 MENUS: HORIZONTAL NAVIGATION BAR CREATING AN HTML LIST

ID1354 Internet Applications

CS 1124 Media computation. Lab 9.3 October 24, 2008 Steve Harrison

Data Visualization (DSC 530/CIS )

Introduction to Web Technologies

The Structure of the Web. Jim and Matthew

What is a web site? Web editors Introduction to HTML (Hyper Text Markup Language)

By Ryan Stevenson. Guidebook #2 HTML

- HTML is primarily concerned with content, rather than style. - However, tags have presentation properties, for which browsers have default values

Project 3 Web Security Part 1. Outline

The building block of a CSS stylesheet. A rule consists of a selector and a declaration block (one or more declarations).

INTRODUCTION TO CSS. Mohammad Jawad Kadhim

Unit 20 - Client Side Customisation of Web Pages. Week 2 Lesson 4 The Box Model

Perfect Student Midterm Exam March 20, 2007 Student ID: 9999 Exam: 7434 CS-081/Vickery Page 1 of 5

Document Object Model. Overview

ICT IGCSE Practical Revision Presentation Web Authoring

HTML and CSS a further introduction

Make a Website. A complex guide to building a website through continuing the fundamentals of HTML & CSS. Created by Michael Parekh 1

COMS 359: Interactive Media

CIS 228 (Spring, 2012) Final, 5/17/12

Creating A Web Page. Computer Concepts I and II. Sue Norris

Static Webpage Development

JavaScript. Like PHP, JavaScript is a modern programming language that is derived from the syntax at C.

In the early days of the Web, designers just had the original 91 HTML tags to work with.

Designing the Home Page and Creating Additional Pages

The default style for an unordered (bulleted) list is the bullet, or dot. You can change the style to either a square or a circle as follows:

COPYRIGHTED MATERIAL. Contents. Chapter 1: Creating Structured Documents 1

HTML TAG SUMMARY HTML REFERENCE 18 TAG/ATTRIBUTE DESCRIPTION PAGE REFERENCES TAG/ATTRIBUTE DESCRIPTION PAGE REFERENCES MOST TAGS

Using Dreamweaver CC. Logo. 4 Creating a Template. Page Heading. Page content in this area. About Us Gallery Ordering Contact Us Links

HTML. HTML Evolution

Creating Web Pages Using HTML

CSS: The Basics CISC 282 September 20, 2014

Transcription:

tmacwilliam@cs50.net October 31, 2011

Announcements pset5: returned final project pre-proposals due Monday 11/7 http://cs50.net/projects/project.pdf CS50 seminars: http://wiki.cs50.net/seminars

Today common pset5 mistakes HTML chmod CSS PHP SQL

Hacker Tip of the Week tired of typing cd ~/cs50/psets/pset5/bmp all the time? ln -s /path/to/target name create a link to a folder! cd into that link, and you ll be in the folder

#1 Design Mistake malloc: with great power comes great responsibility always always always check for NULL when you malloc always. seriously. without a check for NULL, your program could segfault if something goes wrong with malloc then your entire program crashes probably not the best way to respond to an error

#1 Design Mistake malloc: with great power comes great responsibility don t malloc if you don t have to! if what you re malloc-ing is only being accessed in the current function, then just put it on the stack int n = 5; int stack_array[n]; int* heap_array = (int*)malloc(n * sizeo C allows for variable-length array declarations without malloc

HTML HyperText Markup Language used to describe the structure of a document aka, a web page NOT a programming language HTML describes content, but does not create content no ifs, fors, and whiles tells your web browser (Chrome, Firefox, Safari, IE) how to display the content on a web page

HTML HTML consists of a series of embedded elements an element is a single thing on a web page an element is defined by a tag syntax: <tag>this is in the tag!</tag> a tag must have a start and an end everything in between the start and end tag is the content of the tag good style: always close your tags!

HTML common HTML tags a: achor aka hyperlink h1, h2,... h6: headings (h1 like a title, h2 like a subtitle, etc.) p: paragraph b, i, u: bold, italics, underline ul, ol, li: bulleted/numbered lists table, tr, td: tables img: image br: line break div, span: page divisions (for layout) form, input: form elements for text input

HTML that s not all, a valid HTML document also has a particular structure doctype: tells the browser what type of document this is HTML5 doctype: <!doctype html> has no closing tag simply a declaration of the type of file to be used <html>: tells the browser that everything inside will be HTML <head>: tells the browser what to load before the user can interact with the page JavaScript files, CSS stylesheets, page title, etc. no content in the head will actually be displayed to the user <body>: the actual content of the page

HTML example time! skeleton.html

HTML many tags contain attributes, which modify or give specificity to a tag example: I have a hyperlink, but where do I want the page to link to? attributes are specified in key value pairs key= value example: <a href= http://cs50.net >CS50 home page</a>

HTML example time! page.html to view your page from a web browser, it must be in a directory called public_html (or a subdirectory thereof) as a CS50 cloud user, you have a URL at http://cloud.cs50.net/~username

chmod Forbidden: I don t have permission to access? on the could, each file has different permissions (read/write/execute) we need to make sure that only certain users are allowed to edit certain files for us, the words file in pset6 was read-only so we couldn t edit it why are permissions important on a web server?

chmod without permissions, we could allow users to write and execute arbitrary code on our server! aka being hacked by default, all files on the cloud are only readable/writeable by the user who created them so if I create a file on my account and you try to cd to my account and edit it, you ll get a permissions error in order for a user to see our file from a web browser, we need to grant the user permissions

chmod the chmod command allows us to manually specify the permissions for a given file syntax: chmod <permissions> <file> permissions given as an octal number each digit represents a different combination of read/write/execute 3 digits: one for you, one for your group (don t worry about groups), one for the rest of the world

chmod chmod cheat sheet: what permissions does each digit correspond to? 7: read, write, execute 6: read, write 5: read, execute 4: read 3: write, execute 2: write 1: execute 0: no permissions

chmod chmod 600: user can read/write, rest of the world has no permissions PHP files chmod 644: user can read/write, rest of the world can read HTML, JavaScript, CSS, and image chmod 711: user can read/write/execute, rest of the world can execute directories containing public web files

CSS Cascading Style Sheets HTML defines the content and structure of our documents, while CSS defines their style how they look aesthetically: size, color, etc. syntax: <selector> { <attribute>: } <value>;

CSS CSS selectors provide a way to give style properties to a specific element or group of elements to style a specific element, give it an id and/or class attribute example: <img src= logo.png id= logo class= top />

CSS common CSS selectors #<id>: select the element with the given id.<class>: select all elements with the given class <tag>: select all elements with the given tag *: wildcard, select all elements

CSS combining CSS selectors tag.class: select the elements of the given tag with the given class.class1,.class2: select all elements with class class1 or class2 #id <tag> /.class <tag>: select the descendents of the id/class with the given tag

CSS common CSS attributes color: color of an element background: background color/image of an element width / height: size of element margin / padding: space between an element and its containing element font: font size, family, etc.

CSS 3 ways to style your page with CSS create an external stylesheet, then use the <link> tag to add it to the page example: <link rel= stylesheet type= text/css href= style.css /> use the <style> tag example: <style> a { color: red; } </style> use the style attribute example: <p style= width: 300px; >

CSS example time! pagecss.html, pagecss.css

PHP PHP: PHP Hypertext Processor recursive acronyms ftw! web scripting language used to create dynamic web pages static web page: content is the same every time you view it dynamic page: page content depends on user actions, etc. interleaves with HTML pretty nicely

PHP all PHP code must be inside the <?php?> tag syntax very similar to C if (condition) {} else if (condition) {} else {} while (condition) {} for (<pre>; <condition>; <post>) {}

PHP PHP does, however, have small syntactic differences all variable names must start with a dollar sign (e.g. $x = 5;) this will get very annoying, I promise functions/variables are not explicitly given types at declaration example: function increment($x) { return $x + 1 }

PHP arrays in PHP do not have a fixed size add an element to the end of an array: array_push get value of last element and remove it from array: array_pop get value of the first element and remove it from the list: array_shift how can we implement stacks/queues with PHP arrays?

PHP arrays in PHP are also ordered maps (like a hashtable) an integer/string key has an associated value an array can contain keys/values of different types example: $person = array( name => tommy, job => TF, rank => 1);

PHP example time! arrays.php

PHP PHP code can occur anywhere in an HTML document all PHP code on a page will be executed on the server, then the resulting page will be displayed to the user PHP and HTML can be inter-mixed (a lot nicer than using the echo function to write HTML) <?php if ($x == 5):?> <p>x is 5!</p> <?php else:?> <p>x is something else!</p> <?php endif;?>

PHP a class is just like a struct contains multiple fields of different types unlike a struct, a class can contain functions an instance of a class is called an object every class has a special variable called $this that refers to the current instance of the object fields of an object are accessed using -> fields do not include the dollar sign (phew!)

PHP example time! classes.php

PHP when your browser makes a request to a web page, it either makes a GET or POST HTTP request GET: request the content of a web page POST: send data to the web page so the server can do something with it both GET and POST requests can pass arguments to a PHP script GET variables specified right in the url POST variables hidden to the user, sent in POSTDATA field of HTTP request

PHP variables sent to PHP script in key/value pairs PHP can access these variables with the built-in $_GET and $_POST arrays if user accesses the url: file.php?name=tommy&job=tf in file.php: $_GET[ name ] == tommy ; if user submits a form, variables can also be stored in either array form s action attribute determines what script variables should be sent to form s method attribute determines if POST or GET request should be used input s name attribute is key, user s input is value

SQL Structured Query Language pronounced see-kell, saying ess-kew-ell just sounds silly allows the programmer to interact with a database insert new values, retrieve values matching certain parameters, and delete values SQL and PHP are also tightly integrated

SQL a database is a collection of tables a table describes a single type example: a user would be described by a table a table is a collection of fields (columns) example: a users table would have columns for username, password, email, etc. a row in a table is a single instance of something one user would occupy one row in the users table

SQL insert new row: INSERT INTO <table> (<column 1>, <column 2>) VALUES (<value 1>, <value 2>) example: INSERT INTO users (username, password) VALUES ( tommy, supersecret ) delete row: DELETE FROM users WHERE <column> = <value> example: DELETE FROM users WHERE username= djm

SQL modify values in an already existing row: UPDATE <table> SET <column> = <value> WHERE <other column> = <value> example: UPDATE users SET password= evenmoresecret WHERE username= tommy retrieve values: SELECT <column> FROM <table> WHERE <other column> = <value> example: SELECT password FROM users WHERE username= tommy

SQL SQL statements executed via mysql_query phpmyadmin is a web interface for creating/viewing tables accessible at: http://192.168.56.50/phpmyadmin a database for pset7 should already be created for you now you can add new tables and columns to tables

Practice Problems make a web page that displays two 200 pixel squares (one black, one orange) side by side display all the GET variables passed to a PHP script create a form that asks the user for his/her name, then displays it