lec16_php_01.ppt

21
2007 Dr. Natheer Khasawneh CPE 595 Web Application Development PHP and MySQL Part 1

Upload: sampetruda

Post on 10-May-2015

1.544 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

CPE 595Web Application Development

PHP and MySQL Part 1

Page 2: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

What we have covered so far..

• Basic HTML• Basic CSS• Basic JavaScript• Basic DHTML• Very Basic XML

Page 3: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

What We Will Cover Next …

• Basic server-side programming• Basic web-oriented database development• Overview of ‘real world’ web application

development techniques and issues

Page 4: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Web Application

Architectures

Page 5: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Simplified Definition

• A ‘web application’ uses the network as the underlying platform and typically uses a web browser on the client side

Page 6: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Client - Server

• Most web applications use a ‘client-server’ architecture. Clients (users) access application logic running on the server.

Page 7: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

• Within the general web application category there are many different technologies and approaches available for use.

• Server-side programming languages: Java, ASP, Visual Basic, Perl, Ruby, PHP...

• Server-side application platforms: Java Struts, Tomcat, Ruby on Rails, Zope, .NET, commercial offerings from vendors like IBM...

• Databases: MySQL, MS-SQL, Oracle, Postgresql, Filemaker...

• Client-side scripting languages: Javascript/DHTML, Ajax, Macromedia Flash or Director...

• There’s often no one ‘correct’ way to design a web application, though some approaches will probably be more appropriate than others.

Page 8: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

In this class

JavaScript/DHTML Ajax

PHP & MySQL

PHP for dynamic web page

creation, and MySQL

for basic database tasks

Page 9: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Static Vs. Dynamic

• The most basic web sites are ‘static’; they are composed of flat text HTML files living on a server

• The client (browser) requests the file, and software on the server sends the unmodified file to the client. Easy, simple, and not really a ‘web application’.

Page 10: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Static Transaction

User types ‘www.google.com’ into their browser

Browser looks up the domain name, then sends the request to the appropriate server

Software running on server loads the requested file and sends it back to the client

Client receives the file and displays it in the browser

Page 11: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Static Transaction Components

Browser (Internet Explorer, Firefox, Safari) and operating system

DNS system, HTTP (Hypertext Transport Protocol)

Apache or IIS web server software, underlying server operating system

Browser rendering HTML

Page 12: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Client Side Components

• Web browsers are pieces of software that understand HTML markup language (among other things)

• DNS is typically handled by the client operating system, connected to a DNS server, and resolves domain names to IP addresses

• Browsers can use the operating system to send out HTTP requests

Page 13: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Server Side Components

• Servers usually run on more sophisticated versions of standard operating systems. Windows has a server version, OS X has a server version, and Linux is a full-fledged server operating system

• Servers run web server applications such as Apache or Windows IIS. These applications take care of receiving client requests, finding the requested resources, and returning them to the clients (among other things)

Page 14: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Limitations of Static Web Pages

• Static web pages are a ‘one size fits all’ proposition. Everyone has access to the same set of pages.

• Static would make for horrible online banking, ecommerce, web-based email...

Page 15: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Adding dynamic processing

• By adding application logic to the server, we’re able to customize our response to each client request

• Allows us to have a ‘conversation’ with each client based on data sent by the client, data stored on the server, and information exchanged during the ‘conversation’

Page 16: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

And that’s where PHP comes in

• PHP stands for “PHP: Hypertext Preprocessor”. (Yes, the name is recursive)

• Allows us to add programming logic to our HTML pages, processed by our server application(s), that can produce custom HTML on demand.

Page 17: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Understanding the stack

Browsers (Internet Explorer, Firefox, Safari) only understand HTML and some other client-side technologies (Javascript, Flash)

Servers, though, can run any number of applications capable of processing input and output

Page 18: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

What’s happening on the server

• Incoming HTTP request is received by Apache• The HTTP request is for a PHP file• Apache loads the PHP file and runs it through the PHP

parser (application running on the server)• The PHP application runs the PHP code and generates

the output as directed by the PHP code within the HTML file

• The completed HTML-only file is returned by Apache to the browser via HTTP

Page 19: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

A quick example

Output after processing

<html>

<p>Hello there,

ali

</p>

</html>

File on server

<html>

<p>Hello there,

<?php

echo $USERNAME;

?>

</p>

</html>

Don’t worry about the code, just remember that the PHP runs on the server and can create or modify the output displayed by the browser.

Page 20: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Key things to remember

• Client-side browsers do NOT understand server-side languages like PHP or .NET. They understand HTML. So the end output of almost all basic server-side web applications is going to be HTML.

• We’re talking about a simple back and forth application design here; the client and server take turns driving the application. Other approaches, like AJAX, are more complex.

Page 21: Lec16_PHP_01.ppt

2007 Dr. Natheer Khasawneh

Remember where the different technologies live

Server side

Software that can interact with multiple clients and can run your PHP program to allow customized ‘conversations’ with multiple clients

Client side

Browsers that can display HTML and can interact with different servers via HTTP

This is a bit of an oversimplification (in fact, it really oversimplifies modern professional web application development practice, so don’t leave today thinking you’re suddenly an application design architect) but it’s good enough for us to go on for now.