Top Banner
ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY
28

ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Dec 21, 2015

Download

Documents

Marjorie Nash
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

ITC 240: Web Application ProgrammingSUBHASH PRAJAPAT I

06 /29 /15

MSE, SEATTLE UN IVERS ITY

Page 2: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Course Overview• Course Description, Syllabus and Assignments available on Canvas

• Major Resource:o No particular Text book oModules on Canvas as our guideo Class Notes/ Exercises, Slideso Selected Videos/Article Links

• References:o “PHP Solutions: Dynamic Web Design Made Easy” by David Powers (Apress)o Programming PHP – O’Reillyo Or any other beginning PHP books

Page 3: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Course Overview• Grading:o On-class exerciseso AssignmentsoQuizo Project

• Contact oMessage through Canvaso Office Hours: by appointmentso Email: [email protected], [email protected]

Page 4: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Today’s Class• Web Programming

• Client Server Architecture

• Introduction to PHP

• Client Side vs Server Side Language

• How PHP works & PHP Fundamentals

Page 5: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Client Server Architecture

Page 6: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Closer Look: Client Server Architecture

Page 7: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

PHP• Server Side Programming Language for dynamic websites

• Open Source Language

• Initially released as Personal Home Page (PHP) Tool

• Now stands for Hypertext Preprocessor

• Originally developed by Rasmus Lerdorf in 1995 and maintained by PHP team.

• Current Release: 5.6.10 (June 11, 2015)

• Runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)

• Compatible with almost all servers used today (Apache, IIS, etc.)

• Supports a wide range of databases

Page 8: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Popularity PHP is used by 82.0% of all the websites whose server-side programming language we know.

Source: http://w3techs.com/technologies/details/pl-php/all/all

Page 9: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Sites using PHP

• Facebook.com

• Baidu.com

• Wikipedia.org

• Twitter.com

• Tmall.com

• Flickr, Yahoo, Tumblr

Open Source Tools: Wordpress, Drupal, Magento, Joomla, Wiki etc.

Page 10: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

What PHP can do?• Generate dynamic page content

• Command Line Scripting

• Create, open, read, write, delete, and close files (text, image etc.) on the server

• Collect form, validate and store form data

• Send and receive cookies, Send emails

• Add, delete, modify data in your database

• Can encrypt data

• Can be used to control user-access

Page 11: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Class Exercise – 1.1hello.html

<html>

<head><title>PHP Test</title></head>

<body>

<p>Hello World</p>

</body>

</html>

Replace the highlighted line with following and save file as hello.php

<?php echo '<p>Hello World</p>'; ?>

Upload both files (hello.html and hello.php on web server and see the page/view source)

Page 12: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

HTML Source

<html>

<head>

<title>PHP Test</title>

</head>

<body>

<p>Hello World</p>

</body>

</html>

Page 13: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

PHP Syntax

• PHP files have .php extension

• A PHP script starts with <?php and ends with ?>

• A PHP script can be placed anywhere in the document.

• A PHP file normally contains HTML tags, and some PHP scripting code.

• PHP statements end with a semicolon (;)

• PHP Comments

// Single Line Comment

/*

multiple line comment

*/

Page 14: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

HTML/JavaScript/PHP HTML

<p>Hello World</p>

JavaScript

<script>

document.write ('<p>Hello World</p>');

</script>

PHP

<?php

echo '<p>Hello World</p>';

?>

So, What is the difference?

Page 15: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Client Side/Server Side Language

JavaScript: Client Side Language - executes on client side

PHP: Server Side Language - executes on server side, sends result to client

<script>

document.write ('<p>2+3 is '+ (2+3) +'</p>');

</script>

<?php

echo '<p>2+3 is '.(2+3).'</p>';

?>

Both will print: 2+3 is 5 . What is the difference?

Page 16: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Quiz JavaScript

<script>

var d = new Date();

document.write (d.toString());

</script>

PHP

<?php

echo date ('Y/m/d H:i:s');

?>

Q: What will be the output? Why?

Page 17: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

PHP Fundamentals PHP & Text

<div align="center"> <?php echo "Place some PHP here!"; ?> </div>

Interspersing PHP & HTML

<div align="center"> <?php print "<b>This is bold</b>"; ?> </div>

Escaping Character

<?php echo 'We have a customer named O\'Malley'; ?>

Page 18: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

PHP Fundamentals Single vs Double Quotes

With a lot of HTML, we could use single quotes since HTML attributes use lot of double quotes

<?php echo '<div align="center"><font color="red">This has double quotes!</font></div>'; ?>

We could use double quotes with SQL which identifies text (string) data with single quotes.

Page 19: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

PHP FundamentalsStrings

A sequence of characters, like "Hello world!“

<?php echo “hello world”; ?>

String Concatenation

<?php echo “hello”.”world”; ?>

Page 20: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Arithmetic Operators Operation Symbol Example

Negation - -5

Addition + 3+5

Subtraction - 7-4

Multiplication * 5*6

Division / 10/3

Modulus (remainder) % 10%3

Page 21: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Class Exercise – 1.2PHP Arithmetic Operation

<?php

echo "5+2 is ".(5+2);

echo “<br>”;

echo "5-2 is ".(5-2);

echo “<br>”;

echo "5*2 is ".(5*2);

echo “<br>”;

echo "5/2 is ".(5/2);

echo “<br>”;

echo "5%2 is ".(5%2);

echo “<br>”;

?>

Page 22: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Discussion

What would you do if you need to change all the 5s to 10 and all the 2s to 5?

Page 23: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Variables• Storing data into memory location.

• Starts with $ sign

• Can be a single character, multiple characters, numbers etc.

Eg:

<?php

$myName = “Lisa”;

echo $myName;

$a = 5;

$b = 6;

echo $a+$b;

?>

Page 24: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

VariablesSingle quote/ Double quote

values enclosed within single quotation marks will be treated literally, whereas those within double quotation marks will be interpreted

<?

$myNum = 1;

$myOtherNum = 3;

$myTotal = $myNum + $myOtherNum;

echo "You added $myNum and $myOtherNum and the total is $myTotal";

?>

Page 25: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Class Exercise – 1.3 Rewrite the Exercise 1.2 with using variables instead of 5 and 2

For eg:

<?php

$firstNumber = 5;

$secondNumber = 2;

echo “$firstNumber+$secondNumber is ".($firstNumber+$secondNumber);

.

.

?>

Page 26: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Discussion Instead of 5 & 2, we wanted to do calculation of 20 & 10, 40 & 30, 20 & 5 etc.

What would you do?

Page 27: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Function Function is a block of code that performs certain task

<?php

function printName (){ echo “my name is Linda”;

}

printName ();

?>

Page 28: ITC 240: Web Application Programming SUBHASH PRAJAPATI 06/29/15 MSE, SEATTLE UNIVERSITY.

Temporary Resource Site:

http://www.subhash.com.np