WEB Programming
Introduction to PHP
Lec 1
Mohammed Sultan
1
Outlines
• Web Servers
• introduction to PHP
2
WEB SERVERS
3
What is server?
• A server is a computer or device on a network
that manages network resources.
• Most servers are dedicated. This means that
they perform only one task rather than multiple
tasks on multiprocessing operating systems,
however, a single computer can execute several
programs at once
4
What is web server?
• A Web server is a program that generates and
transmits responses to client requests for Web
resources.
5
How do Web Servers work?
• Client specifies document at a specific web
address that is desired (specified by a URL)
– Ex: http://www.Aljanad_univ.edu/
• If the document is HTML or text, the server
simply forwards it back to the client
– If it is text, it is shown unaltered in the browser
– If it is HTML it is rendered in the client's browser
• HTML tags are interpreted and result is shown to the user
6
How do Web Servers work?
• However, the requested document may be an
executable script, or it may be HTML with an
embedded script
• In these cases, the server executes the script
– If the entire document was a script, the server simply
sends the output back to the client
– If the document had an embedded script, the script
sections are replaced with the output and the
modified document is then sent to the client
7
How do Web Servers work?
• Note that the client never sees the server-side
script code
– This is important – typically client should not see
logic / code that the server executes to process
requests
– The server may be accessing files whose names
should not be seen, or preprocessing data that it
does not want the client to see
8
Web Site versus Web Server?
• Web site and Web server are different:
– A Web site consists of a collection of Web pages
associated with a particular hostname.
– A Web server is a program to satisfy client
requests for Web resources.
9
Types Of Web Servers
1. Apache Web Server
2. IIS Server
3. Xampp Server
4. WAMP Server
10
Apache Web Server
• Apache Web server is the most commonly used http
server today. About 80% of all websites and Intranets use
Apache web server to deliver their content to requesting
Browsers.
• Server side programming languages such as PHP, Perl,
Python, Java and many others
• Apache is free software distributed by the Apache
Software Foundation. The Apache Software Foundation
promotes various free and open source advanced Web
technologies.
11
Hypertext preprocessing
PHP
12
What is PHP?
• PHP is an acronym for "PHP: Hypertext Preprocessor"
• Language developed by Rasmus Lerdorf from the
Apache Group (1994)
• Open Source
– In general, open source refers to any program whose
source code is made available for use or modification.
– Open source software is usually developed as a public
collaboration and made freely available.
• PHP is a HUGE language
• It is a fully functional language
• It has an incredible amount of built-in features
13
What is PHP?
• PHP runs on various platforms (Windows,
Linux, Unix, Mac OS X, etc.)
• PHP is compatible with almost all servers used
today (Apache, IIS, etc.)
• PHP supports a wide range of databases
– Ex:Mysql
14
History
The PHP version 4.0 was launched in May 2000.
This version includes session handling, output
buffering, a richer cire language and support for
wide variety of web server platforms.
• The PHP 5.0 version released in 2004 with
object oriented programming concept.
15
What's new in PHP 7?
• PHP 7 is much faster than the previous popular
stable release (PHP 5.6)
• PHP 7 has improved Error Handling
• PHP 7 supports stricter Type Declarations for
function arguments
• PHP 7 supports new operators (like the spaceship
operator: <=>)
16
What Do I Need?
• Find a web host with PHP and MySQL support
• Install a web server on your own PC, and then
install PHP and MySQL
• Set Up PHP on Your Own PC:
– install a web server
– install PHP
– install a database, such as MySQL
Because PHP is free, most web hosts offer PHP
support. 17
What is PHP?
• PHP scripts execute on web server and serve
WebPages to user on request.
• Its primary use is for server-side scripting
– To process HTML forms
– To perform a DB query and pass on results
18
What is PHP?
• PHP scripts are often embedded within HTML
documents
• The server processes the HTML document,
executing the PHP segments and substituting
the output within the HTML document
19
PHP Program Structure
• PHP, as with many scripting languages, does
not have nearly the same structural
requirements as a language like Java
• A script can be just a few lines of code or a
very large, structured program with classes
and objects
– The complexity depends on the task at hand
20
PHP Program Structure
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
21
PHP Program Structure
<!DOCTYPE html>
HTML5 Document
<html> HTML root
<head>
<title>Simple PHP Example</title> HTML Head
</head>
<body>
<?php
echo "<p><h1>Output</h1>";
echo "<h2>Output</h2>";
?>
PHP Code
<script language="PHP">
echo "\n<b>More PHP Output</b>\n";
</script>
</body>
</html>
22
PHP Program Structure
• If we prefer to separate a PHP code segment
from the rest of our script, we can write it in
another file and include it
– Sometimes it is easier if we "separate" the PHP
code from the straight html
23
What is a PHP File?
• PHP files can contain text, HTML, CSS,
JavaScript, and PHP code
• PHP code is executed on the server, and the
result is returned to the browser as plain
HTML
• PHP files have extension ".php"
24
Downloading
• The official PHP website (PHP.net) has installation instructions for
PHP:
– www.php.net
– http://php.net/manual/en/install.php
– PHP7
• Download Apache Web Server:
– The latest stable build of Apache http server can be downloaded from
• URLhttp://httpd.apache.org
• Download Mysql :
– https://www.mysql.com ›
– MySQL 8.0
25
Any Questions?
26