lec16_php_01.ppt
TRANSCRIPT
2007 Dr. Natheer Khasawneh
CPE 595Web Application Development
PHP and MySQL Part 1
2007 Dr. Natheer Khasawneh
What we have covered so far..
• Basic HTML• Basic CSS• Basic JavaScript• Basic DHTML• Very Basic XML
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
2007 Dr. Natheer Khasawneh
Web Application
Architectures
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
2007 Dr. Natheer Khasawneh
Client - Server
• Most web applications use a ‘client-server’ architecture. Clients (users) access application logic running on the server.
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.
2007 Dr. Natheer Khasawneh
In this class
JavaScript/DHTML Ajax
PHP & MySQL
PHP for dynamic web page
creation, and MySQL
for basic database tasks
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’.
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
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
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
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)
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...
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’
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.
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
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
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.
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.
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.