Server side basics CSC 210

Similar documents
URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser:

Server side basics CS380

Web Programming Step by Step

The 2017 Top Programming Languages

Lecture 12. PHP. cp476 PHP

CSCB20 Week 8. Introduction to Database and Web Application Programming. Anna Bretscher* Winter 2017

EECS1012. Net-centric Introduction to Computing. Crash Course on PHP

Lecture 7 PHP Basics. Web Engineering CC 552

CSC Web Programming. Introduction to JavaScript

PHP: The Basics CISC 282. October 18, Approach Thus Far

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

PHP. Interactive Web Systems

What is PHP? [1] Figure 1 [1]

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

B. V. Patel Institute of BMC & IT 2014

Preview from Notesale.co.uk Page 3 of 79

C++ Programming: From Problem Analysis to Program Design, Third Edition

CSCB20 Week 8. Introduction to Database and Web Application Programming. Anna Bretscher* Winter 2016

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

PHP by Pearson Education, Inc. All Rights Reserved.

IDM 232. Scripting for Interactive Digital Media II. IDM 232: Scripting for IDM II 1

Such JavaScript Very Wow

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

Mobile Site Development

BEGINNER PHP Table of Contents

Creating HTML files using Notepad

Introduction to Git and GitHub for Writers Workbook February 23, 2019 Peter Gruenbaum

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

CERTIFICATE IN WEB PROGRAMMING

CSc 337 LECTURE 5: GRID LAYOUT AND JAVASCRIPT

Python Programming Exercises 1

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Princeton University COS 333: Advanced Programming Techniques A Subset of PHP

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP?

COMS 469: Interactive Media II

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

EL2310 Scientific Programming

COMS 469: Interactive Media II

JavaScript: The Basics

Software Development I

CS313D: ADVANCED PROGRAMMING LANGUAGE

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

PHP. Introduction. PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

printf( Please enter another number: ); scanf( %d, &num2);

Programming for the Web with PHP

Programming Language. Functions. Eng. Anis Nazer First Semester

COMP519 Practical 15 PHP (1)

JavaScript CS 4640 Programming Languages for Web Applications

What did we talk about last time? Examples switch statements

Object-Oriented Programming

COMS 469: Interactive Media II

Web Scripting using PHP

Course Outline. Introduction to java

CGS 3066: Spring 2015 JavaScript Reference

Web Scripting using PHP

QUIZ: What value is stored in a after this

- Origins - Rasmus Lerdorf Developed to allow him to track visitors to his Web site

Visual C# Instructor s Manual Table of Contents

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

Python for Astronomers. Week 1- Basic Python

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

Python Input, output and variables

Language Reference Manual

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

Chapter 17. Fundamental Concepts Expressed in JavaScript

Reading How the Web Works

COMP284 Scripting Languages Lecture 9: PHP (Part 1) Handouts

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

SPARK-PL: Introduction

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

INTERNET PROGRAMMING. Software Engineering Branch / 4 th Class Computer Engineering Department University of Technology

Lecture (05) PHP 01. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Spring 2016, Web Programming

PHP 1. Introduction Temasek Polytechnic

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Values and Variables 1 / 30

Chapter 2: Using Data

Week 6: Review. Java is Case Sensitive

CSI33 Data Structures

Introduction to TURING

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

A Web-Based Introduction

Ruby on Rails Welcome. Using the exercise files

Git & Github Fundamental by Rajesh Kumar.

Introduction to Programming Using Java (98-388)

JAVASCRIPT BASICS. JavaScript String Functions. Here is the basic condition you have to follow. If you start a string with

Git. Charles J. Geyer School of Statistics University of Minnesota. Stat 8054 Lecture Notes

Program Fundamentals

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

Full file at

JavaScript CS 4640 Programming Languages for Web Applications

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

HTML5 and CSS3 More JavaScript Page 1

Language Reference Manual simplicity

Sequence of Characters. Non-printing Characters. And Then There Is """ """ Subset of UTF-8. String Representation 6/5/2018.

Working with JavaScript

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Transcription:

1 Server side basics

Be careful 2 Do not type any command starting with sudo into a terminal attached to a university computer. You have complete control over you AWS server, just as you have complete control over your laptop. University computers are shared sudo overrides protection of other users of the computer.xs

SM: Initialize Git on Betaweb 3 AWS$ pwd! /home/ec2-user/! AWS$ git clone <you>@betaweb.csug.rochester.edu:/p/ csc210/<your team repo>! AWS$ cd <your team repo>! AWS$ cp -r /var/www/html/*.! AWS$ git add.! AWS$ git status! AWS$ git commit! AWS$ git push origin master! Send email to team telling them that you have set up the master directory on Betaweb

Everyone: Getting Betaweb to AWS 4 AWS> pwd! /home/ec2-user/! AWS> git clone <you>@betaweb.csug.rochester.edu:/p/ csc210/<your team repo>! AWS> cd <your team repo>! AWS> ls!! Is everything there?

Everyone: Create personal branch 5 $ git branch! * master! $ git branch martin! $ git branch! martin! * master! $ git checkout martin! Switched to branch 'martin! $ git branch! * martin! master!!

Git diagram 6

Everyone: Editing a file 7 $ cd 0! $ emacs index.html! $ cat index.html!...! <p>! (describe what you did, including any extra credit, here.)!! Added this to my branch on AWS! </p>!...!!!

Everyone: Checking in work 8 $ git add index.html! $ git status! # On branch martin! # Changes to be committed:!! $ git commit! $ git push origin martin! martin@betaweb.csug.rochester.edu s password:!!!

SM: Setting up as SM 9 betaweb$ pwd! /home/<scrum master s home>! betaweb $ git clone /p/csc210/<your team repo>! betaweb $ git branch! * master! betaweb $ git branch staging! betaweb $ git branch -a! * master! staging! remotes/origin/head -> origin/master! remotes/origin/martin! remotes/origin/master!!

SM: Merging work 10 $ git checkout <branch with new work>! $ git pull origin martin! $ git checkout staging! $ git merge martin! $ git push origin staging!!

SM: Testing new work in staging 11 $ pwd! /home/ec2-user/<your team repo>! $ git branch staging! $ git checkout staging! $ git pull origin staging! $ cp r./* /var/www/html/!!!

SM: Testing new work 12

SM: Testing new work in staging 13 $ pwd! /home/ec2-user/<your team repo>! $ emacs index.html!...! <p>! (describe what you did, including any extra credit, here.)! <p>! </p>! Added this to my branch on AWS! </p>!!!

SM: Testing new work in staging 14

SM: Merging into Master 15 $ git add index.html! $ git commit! $ git push origin staging! <user>@betaweb.. Password:! $ git checkout master! $ git merge staging! $ git push origin master! Betaweb password:!! Send email to team saying that the Master has been updated

Quiz 16 Write CSS code put a paragraph: in the horizontal center of the page, occupying half the page s width, and right-aligning the paragraph s text? What is the difference between display: none and visibility: hidden Is PHP code static or dynamic web content? Given <?php $bar = foo? > write a php block that will put foo on the page.

Quiz Answers 17 1. p { margin-left: auto; } margin-right: auto; width: 50%; 2. display: none leaves no space; visibility: hidden leaves space. 3. PHP is dynamic web content? 4. <?php $bar?>

18 Server side basics

URLs and web servers 19 http://server/path/file Usually when you type a URL in your browser: Your computer looks up the server's IP address using DNS Your browser connects to that IP address and requests the given file The web server software (e.g. Apache) grabs that file from the server's local file system The server sends back its contents to you

URLs and web servers (cont.) 20 Apache, Websphere SW(Java Servlets, XML Files) Web/Application Server Database

URLs and web servers (cont.) 21 http://www.facebook.com/home.php Some URLs actually specify programs that the web server should run, and then send their output back to you as the result: The above URL tells the server facebook.com to run the program home.php and send back its output

Server-Side web programming 22 Server-side pages are programs written using one of many web programming languages/frameworks examples: PHP, Java/JSP, Ruby on Rails, ASP.NET, Python, Perl

Server-Side web programming (cont.) 23 Also called server side scripting: Dynamically edit, change or add any content to a Web page Respond to user queries or data submitted from HTML forms Access any data or databases and return the results to a browser Customize a Web page to make it more useful for individual users Provide security since your server code cannot be viewed from a browser

Server-Side web programming (cont.) 24 Web server: contains software that allows it to run server side programs sends back their output as responses to web requests Each language/framework has its pros and cons we use PHP

What is PHP? 25 PHP stands for "PHP Hypertext Preprocessor" Server-side scripting language Used to make web pages dynamic: provide different content depending on context interface with other services: database, e-mail, etc. authenticate users process form information PHP code can be embedded in XHTML code

Lifecycle of a PHP web request 26 Hello world! Hello.php User s computer Server computer

Why PHP? 27 Free and open source Compatible as of November 2006, there were more than 19 million websites (domain names) using PHP. Simple

Hello World! 28 <?php print "Hello, world!";?> PHP Hello world! output

Viewing PHP output 29 Hello world!

30 PHP Basic Syntax

PHP syntax template 31 HTML content <?php PHP code?> HTML content <?php PHP code?> HTML content... PHP Contents of a.php file between <?php and?> are executed as PHP code All other contents are output as pure HTML We can switch back and forth between HTML and PHP "modes"

Console output: print 32 print "text"; print "Hello, World!\n"; print "Escape \"chars\" are the SAME as in Java!\n"; print "You can have line breaks in a string."; print 'A string can use "single-quotes". It\'s cool!'; PHP PHP Hello world! Escape "chars" are the SAME as in Java! You can have line breaks in a string. A string can use "single-quotes". It's cool! output

Variables 33 $name = expression; $user_name = mundruid78"; $age = 16; $drinking_age = $age + 5; $this_class_rocks = TRUE; PHP PHP names are case sensitive names always begin with $, on both declaration and usage always implicitly declared by assignment (type is not written) a loosely typed language (like JavaScript or Python)

Variables 34 basic types: int, float, boolean, string, array, object, NULL test type of variable with is_type functions, e.g. is_string gettype function returns a variable's type as a string PHP converts between types automatically in many cases: string int auto-conversion on + int float auto-conversion on / type-cast with (type): $age = (int) "21";

Arithmetic operators 35 + - * / %. ++ -- = += -= *= /= %=.= many operators auto-convert types: 5 + "7" is 12

Comments 36 # single-line comment // single-line comment /* multi-line comment */ PHP like Java, but # is also allowed a lot of PHP code uses # comments instead of //

String Type 37 $favorite_food = "Ethiopian"; print $favorite_food[2]; $favorite_food = $favorite_food. " cuisine"; print $favorite_food; PHP zero-based indexing using bracket notation there is no char type; each letter is itself a String string concatenation operator is. (period), not + 5 + "2 turtle doves" === 7 5. "2 turtle doves" === "52 turtle doves" can be specified with "" or ''

String Functions 38 # index 0123456789012345 $name = "Stefanie Hatcher"; $length = strlen($name); $cmp = strcmp($name, "Brian Le"); $index = strpos($name, "e"); $first = substr($name, 9, 5); $name = strtoupper($name); PHP

String Functions (cont.) 39 Name strlen strpos substr strtolower, strtoupper trim explode, implode strcmp Java Equivalent length indexof substring tolowercase, touppercase trim split, join compareto

Interpreted Strings 40 $age = 16; print "You are ". $age. " years old.\n"; print "You are $age years old.\n"; # You are 16 years old. PHP strings inside " " are interpreted variables that appear inside them will have their values inserted into the string strings inside ' ' are not interpreted: print ' You are $age years old.\n '; # You are $age years old. \n PHP

Interpreted Strings (cont.) 41 print "Today is your $ageth birthday.\n"; # $ageth not found print "Today is your {$age}th birthday.\n"; PHP if necessary to avoid ambiguity, can enclose variable in {}

Interpreted Strings (cont.) 42 $name = Xenia"; $name = NULL; if (isset($name)) { print "This line isn't going to be reached.\n"; } PHP a variable is NULL if it has not been set to any value (undefined variables) it has been assigned the constant NULL it has been deleted using the unset function can test if a variable is NULL using the isset function NULL prints as an empty string (no output)

for loop (same as Java) 43 for (initialization; condition; update) { statements; } PHP for ($i = 0; $i < 10; $i++) { print "$i squared is ". $i * $i. ".\n"; } PHP

bool (Boolean) type 44 $feels_like_summer = FALSE; $php_is_great = TRUE; $student_count = 7; $nonzero = (bool) $student_count; # TRUE the following values are considered to be FALSE (all others are TRUE): 0 and 0.0 (but NOT 0.00 or 0.000) "", "0", and NULL (includes unset variables) arrays with 0 elements FALSE prints as an empty string (no output); TRUE prints as a 1 PHP

if/else statement 45 if (condition) { statements; } elseif (condition) { statements; } else { statements; } PHP

while loop (same as Java) 46 while (condition) { statements; } PHP do { statements; } while (condition); PHP

Math operations 47 $a = 3; $b = 4; $c = sqrt(pow($a, 2) + pow($b, 2)); PHP math functions abs ceil cos floor log log10 max min pow rand round sin sqrt tan math constants M_PI M_E M_LN2

Int and Float Types 48 $a = 7 / 2; # float: 3.5 $b = (int) $a; # int: 3 $c = round($a); # float: 4.0 $d = "123"; # string: "123" $e = (int) $d; # int: 123 PHP int for integers and float for reals division between two int values can produce a float

PHP exercise 1 49 For your first PHP exercise, echo the following statement to the browser: Twinkle, Twinkle little star. Next, create two variables, one for the word Twinkle and one for the word star. Echo the statement to the browser, this time substituting the variables for the relevant words. Change the value of each variable to whatever you like, and echo the statement a third time. Remember to include code to show your statements on different lines.

PHP exercise 2 50 PHP includes all the standard arithmetic operators. For this PHP exercise, you will use them along with variables to print equations to the browser. In your script, create the following variables: $x=10; $y=7; Write code to print out the following: 10 + 7 = 17 10-7 = 3 10 * 7 = 70 10 / 7 = 1.4285714285714 10 % 7 = 3 Use numbers only in the above variable assignments, not in the echo statements.

PHP exercise 3 51 Arithmetic-assignment operators perform an arithmetic operation on the variable at the same time as assigning a new value. For this PHP exercise, write a script to reproduce the output below. Manipulate only one variable using no simple arithmetic operators to produce the values given in the statements. Hint: In the script each statement ends with "Value is now $variable." Value is now 8. Add 2. Value is now 10. Subtract 4. Value is now 6. Multiply by 5. Value is now 30. Divide by 3. Value is now 10. Increment value by one. Value is now 11. Decrement value by one. Value is now 10.

PHP exercise 4 52 When you are writing scripts, you will often need to see exactly what is inside your variables. For this PHP exercise, think of the ways you can do that, then write a script that outputs the following, using the echo statement only for line breaks. string(5) "Harry" Harry int(28) NULL

PHP exercise 5 53 For this PHP exercise, write a script using the following variable: $around="around"; Single quotes and double quotes don't work the same way in PHP. Using single quotes (' ') and the concatenation operator, echo the following to the browser, using the variable you created: What goes around, comes around.

PHP exercise 5 54 In this PHP exercise, you will use a conditional statement to determine what gets printed to the browser. Write a script that gets the current month and prints one of the following responses, depending on whether it's August or not: It's August, so it's really hot. Not August, so at least not in the peak of the heat. Hint: the function to get the current month is 'date('f', time())' for the month's full name.

PHP exercise 6 55 Loops are very useful in creating lists and tables. In this PHP exercise, you will use a loop to create a list of equations for squares. Using a for loop, write a script that will send to the browser a list of squares for the numbers 1-12. Use the format, "1 * 1 = 1", and be sure to include code to print each formula on a different line.

PHP exercise 7 56 HTML tables involve a lot of repetitive coding - a perfect place to use for loops. You can do even more if you nest the for loops. In this PHP exercise, use two for loops, one nested inside another. Create the following multiplication table: 1 2 3 4 5 6 7 2 4 6 8 10 12 14 3 6 9 12 15 18 21 4 8 12 16 20 24 28 5 10 15 20 25 30 35 6 12 18 24 30 36 42 7 14 21 28 35 42 49