2
Server Side Technologies
Server-side technologies are quite numerous and diverse.
Popular server side web application technologies include:
– Microsoft ASP/.NET
– Java server technologies such as J2EE, JSP, and servlets
– Perl
– PHP
– ColdFusion
• The “core” server side application development
platforms can retrieve, modify and query the contents of
databases through their own access mechanisms:
• PHP enables direct access to many existing DB
platforms, most notably MySQL, but also,
Oracle, SQL Server and others
3.
3
Dynamic Web pageneeded when:
– consistent look and feel on each page of a large
site is required
– data is derived from a database
– content depends on real time
– content depend on user choice
– business transactions e.g. e-commerce…
4.
4
How PHP Pagesare Accessed
and Interpreted
Client: Web browser Web server
1.Form submitted with a submit button
2.----- Action sends a request to the php file in server
3. Receive the request, find the file,
and read it
4. Execute the PHP commands
5. Send the results back
6. ---- results returned as HTML file
7. Web browser renders the HTML file, displaying the results
6
3-Tier Architecture &PHP Scripting
PHP script
Web Server
(Apache, IIS)
Browser
(IE, FireFox,
Opera)
Desktop
(PC or MAC)
Database
Database
Server
SQL
HTTP
HTML tables
DHTML
vision
touch
voice
Presentation
Layer
Application
Layer
Persistence
Layer
7.
7
3-tier architecture
• APresentation layer using Browser technology
– Decoding URLs : protocol/host/file
– Host name converted to IP address(164.11.8.19)
– Issue request to remote server using appropriate protocol (usually HTTP)
– accept the returned HTML (or JPEG, ..) file
• An Application layer using a web application server platform + application
programs
– Server (Apache, IIS)
• Identifying appropriate action to take – fetch a file, pass request to an
interpreter
– Server Script (e.g. in PHP)
• Interacting with the server (accessing input and generating output)
• interpreting the requests according to business rules and past transactions
from this client
• A Persistence layer using a relational database or other data store technology
– interaction with the database using standard languages e.g. SQL queries using
database-specific protocol over TCP/IP
– define and modify the data structures (e.g. tables) themselves
( the Database Schema)
– insert, update and delete data
– maintain data persistently, with backup and recovery
8.
8
Web page designand production
Major steps in Web page design and
production:
1. Define audiences and the information
requirements
2. Develop logical design of the Web site
3. Develop the perceptual design
4. Content creation
5. Programming
6. Posting and hosting the site
9.
9
History of PHP
•Started as a Perl hack in 1994 by Rasmus Lerdorf (to
handle his resume), developed to PHP/FI 2.0
• 1994: Created by Rasmis Lesdorf, software engineer
(part of Apache Team)
• 1995: Called Personal Home Page Tool, then released
as version 2 with name PHP/FI (Form Interpreter, to
analyze SQL queries)
• By 1997 up to PHP 3.0 with a new parser engine by
Zeev Suraski and Andi Gutmans
• Half 1997: used by 50,000 web sites
• October 1998: used by 100,000 websites
• End 1999: used by 1,000,000 websites
10.
10
History of PHP(cont.)
Version 5.2.4 is current version, rewritten by Zend
(www.zend.com) to include a number of features,
such as an object model
Version 5.0 will include version 2.0 of the Zend
Engine
• New object model is more powerful
• Objects will no longer be passed by value; they now
will be passed by reference
• Increases performance and makes OOP more attractive
Current is version 5 that known as PHP 5
PHP is one of the premier examples of what an open
source project can be
11.
11
About Zend
• ACommercial Enterprise
• Zend provides Zend engine for PHP for free
• They provide other products and services for a
fee
– Server side caching and other optimizations
– Encoding in Zend's intermediate format to protect
source code
– IDE-a developer's package with tools to make life
easier
– Support and training services
• Zend's web site is a great resource
12.
12
2.1 what isPHP?
• PHP is a stand for " Hypertext Preprocessor".
• PHP is a server side scripting language that is
embedded in HTML. It is used to manage dynamic
content, databases, session tracking, even build entire
e-commerce sites.
• It is integrated with a number of popular databases,
including MySQL, Oracle, Sybase, Informix, and
Microsoft SQL Server.
• PHP supports a large number of major protocols such
as POP3,FTP ,HTTP and so on
• PHP is a widely-used, open source scripting language
13.
13
what is PHP?(cont.)
• PHP scripts are executed on the server
• It is an interpreted, server-side scripting language.
• Originally designed for web development.
• PHP Syntax is similar to C, Perl/Practical extraction and
Report Language / , java and so on
• PHP is case sensitive
• PHP scripts reside between reserved PHP tags
• The PHP Source-code not visible by client
– ‘View Source’ in browsers does not display the PHP
code
• PHP:Various built-in functions allow for fast development
• PHP is Compatible with many popular databases
14.
14
Alternatives to PHPOR Similar
languages
• Similar languages are :
–Perl/Practical extraction and Report
Language /
–ASP.NET,
–Ruby,
–JSP (JavaServer Pages) ,
–Active Server Pages (ASP) and etc...
16
Common uses ofPHP
• PHP performs system functions, i.e. from files on a
system it can create, open, read, write, and close them.
• PHP can handle forms, i.e. gather data from files, save
data to a file, through email you can send data, return
data to the user.
• You add, delete, modify elements within your
database through PHP.
• Access cookies variables and set cookies.
• Using PHP, you can restrict users to access some
pages of your website.
• It can encrypt data.
17.
17
What Can PHPDo?
• PHP can generate dynamic page content
• PHP can create, open, read, write, delete, and
close files on the server
• PHP can collect form data
• PHP can send and receive cookies
• PHP can add, delete, modify data in your database
• PHP can be used to control user-access
• PHP can encrypt data
– With PHP you are not limited to output HTML. You
can output images, PDF files, and even Flash
movies. You can also output any text, such as
XHTML and XML.
18.
18
Characteristics of PHP
•Five important characteristics make PHP's
practical nature possible −
– Simplicity
– Efficiency
– Security
– Flexibility
– Familiarity
19.
19
What is aPHP File?
–PHP files can contain text, HTML,
CSS, JavaScript, and PHP code
–PHP code are executed on the server,
and the result is returned to the browser
as plain HTML
–PHP files have extension ".php"
20.
20
Why Choose PHP?/ Why PHP?
• Open source, free software ,PHP is free. Download it from
the official PHP resource: www.php.net
• PHP supports a wide range of databases
• PHP runs on various platforms (Windows, Linux, Unix,
Mac OS X, etc.)
• PHP is compatible with almost all servers used today
(Apache, IIS, etc.)
• Powerful, robust/ strong and scalable
– Example Yahoo, Facebook, and Wikipedia
• Designed for web page
• Can be object oriented
• PHP is easy to learn and runs efficiently on the server side
21.
21
PHP Features
• Performance
–Relatively fast for an interpreted language.
• Database Connectivity
– Support for MySQL, Oracle, dbm, DB2, PostgreSQL
– Can connect to any database which provides an ODBC driver (Open
Database Connectivity Standard) – e.g. MS Access
• Existing Libraries
– PHP was originally designed for web use – lots of functions for common
web-development tasks (e.g. Sending email, XML parsing, etc.)
• Portability
– Supported on Windows, Mac OS X, other Unix-like systems (e.g. Linux).
• Object-Oriented Programming
– Similar syntax and features as C++ and Java – inheritance, attribute
visibility (private, protected), abstract classes/methods, constructors and
destructors, etc.
• Popularity
– As a result, lots of documentation, books, and web tutorials.
22.
22
PHP Usage
• Server-SideScripting Language
–Must have a web server and the PHP
interpreter installed.
• Appach / clashfish web server
• Zend engine interpreter
–PHP interpreter processes pages before they
are served to clients.
23.
23
PHP advantages
Advantages ofUsing PHP to enhance Web
pages:
– Easy to use
– Simpler than Perl
– Open source
– Multiple platform.
24.
24
PHP - SyntaxOverview
Escaping to PHP
• The PHP analyzing engine needs a way to
differentiate PHP code from other elements in the
page.
• The mechanism for doing so is known as 'escaping to
PHP'. There are four ways to do this: −
1. Canonical PHP tags
2. Short-open (SGML-style) tags
3. ASP-style tags
4. HTML script tags
25.
25
Canonical PHP tags
–The most universally effective PHP tag style is −
– <?php...?>.
Short-open (SGML-style) tags
– Short or short-open tags look like this −
– <?...?> or <? // Some code?>
ASP-style tags
– Active Server Pages /ASP-style tags look like this −
– <%...%>
HTML script tags
– HTML script tags look like this −
– <script language="PHP">...</script>
26.
26
Basic Syntax ofPHP 5
• A PHP script can be placed anywhere in the
document.
• A PHP script starts with
<?php and ends with ?> :
28
PHP echo andprint Statements
• The PHP echo Statement
– echo is a language construct, and can be used with or
without parentheses: echo or echo().
• Echo uses display text, variable and Strings
– The following example shows how to display different
strings with the echo command (also notice that the strings
can contain HTML markup):
Example:
<?php
echo "<h2>PHP is fun!</h2>";
echo "Hello world!<br>";
echo "This", " string", " was", " made", " with multiple parameters.";
?>
echo "Go Bisons";
echo("Go Bisons"); // same thing
29.
29
PHP print Statements
–print is also a language construct, and can be used
with or without parentheses: print or print().
• Print uses display text, variable and Strings
– The following example shows how to display
different strings with the print command (also
notice that the strings can contain HTML markup):
Example Example: parentheses
<?php
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
print ( "Your message to print" );
Enclose message
in quotation
marks
Message to Output
End in a
semi-colon
Parenthesis are
optional
31
PHP is whitespaceinsensitive
• Whitespace is the stuff / fill something you type that is
typically invisible on the screen, including spaces, tabs, and
carriage returns (end-of-line characters).
• PHP whitespace insensitive means that it almost never
matters how many whitespace characters you have in a
row.one whitespace character is the same as many such
characters.
• For example, each of the following PHP statements that assigns the
sum of 2 + 2 to the variable $four is equivalent: −
$four = 2 + 2; // single spaces
$four <tab>=<tab>2<tab>+<tab>2 ; // spaces and tabs $four
= 2+ 2; // multiple lines
32.
32
PHP 5 variable
•Store values for future reference, use variable name to
refer to the value stored in it
• Variables are "containers" for storing information.
• Creating (Declaring) PHP Variables
– In PHP, a variable starts with the $ sign, followed by the name
of the variable:
– Example
$x = 42; // store the value 42 in $x
echo $x; // prints 42
echo $x+1; // prints 43, value of $x is still 42
$x = ‘hello!’ // type of $x can change
• PHP is a loosely-typed language
– Do not need to declare the type of a variable !
– Type can change throughout the program
33.
33
PHP is aLoosely Type Language
• In the example above, notice that we did not
have to tell PHP which data type the variable
is.
• PHP automatically converts the variable to the
correct data type, depending on its value.
• In other languages such as C, C++, and Java,
the programmer must declare the name and
type of the variable before using it.
34.
34
Rules for PHPvariables:
• A variable name must start with a letter or the
underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive ($age and
$AGE are two different variables)
36
PHP Variables Scope
•In PHP, variables can be declared anywhere in the script.
• PHP has three different variable scopes:
– local
• A variable declared within a function has a LOCAL SCOPE and can
only be accessed within that function:
– global
• A variable declared outside a function has a GLOBAL SCOPE and can
only be accessed outside a function:
– static
• Normally, when a function is completed/executed, all of its variables
are deleted. However, sometimes we want a local variable NOT to be
deleted. We need it for a further job.
• To do this, use the static keyword when you first declare the variable:
37.
37
Example: global scope
•<?php
$x = "color:red">5; // global scope
function myTest() {
}
myTest();
echo"<p>Variable x outside function is:
$x</p>";
?>
38.
38
Example: local scope
•<?php
"color:mediumblue">function myTest() {
$x = "color:red">5; "color:green">// local scope
"color:mediumblue">echo "color:brown">"<p>Variable x inside
function is: $x</p>";
}
myTest();
"color:green">// using x outside the function will generate an error
"color:mediumblue">echo "color:brown">"<p>Variable x outside
function is: $x</p>";
"color:red">?>
40
PHP Data Types
•Variables can store data of different types, and
different data types can do different things.
• PHP supports the following data types:
– String
– Integer
– Float (floating point numbers - also called double)
– Boolean
– Array
– Object
– NULL
– Resource
41.
41
PHP String
• Astring is a sequence of characters, like "Hello world!".
• A string can be any text inside quotes. You can use
single or double quotes:
• Example
<?php
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
?>
42.
42
PHP Integer
• Aninteger data type is a non-decimal number between -
2,147,483,648 and 2,147,483,647.
• Rules for integers:
– An integer must have at least one digit
– An integer must not have a decimal point
– An integer can be either positive or negative
– Integers can be specified in three formats: decimal (10-based),
hexadecimal (16-based - prefixed with 0x) or octal (8-based -
prefixed with 0)
• In the following example $x is an integer.
• The PHP var_dump() function returns the data type and
value:
43.
43
PHP Float
• Afloat (floating point number) is a number with
a decimal point or a number in exponential form.
• In the following example $x is a float.
– The PHP var_dump() function returns the data type
and value:
Example
<?php
$x = 10.365;
var_dump($x);
?>
44.
44
PHP Boolean
• ABoolean represents two possible states:
TRUE or FALSE.
• $x = true;
$y = false;
• Booleans are often used in conditional testing.
• is_bool($x):it mean the variable value $x is
true.
45.
45
PHP Array
• Anarray stores multiple values in one single variable.
– An ordered integer indexed collection of objects.
• In the following example $cars is an array.
• The PHP var_dump() function returns the data type
and value:
<?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
• Php 5.4 added the short array syntax.
– $array=[1,2,3];
46.
46
PHP Object
• Anobject is a data type which stores data and information on how to
process that data.
• In PHP, an object must be explicitly declared.
<?php
class Car {
function Car() {
$this->model = "VW";
}
}
// create an object
$herbie = new Car();
// show object properties
echo $herbie->model;
?>
47.
47
NULL
• Null isa special data type which can have only one value:.
• A variable of data type NULL is a variable that has no value
assigned to it.
• Tip: If a variable is created without a value, it is
automatically assigned a value of NULL.
• Variables can also be emptied by setting the value to NULL:
<?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
48.
48
PHP Strings
• Astring is a sequence of characters, like "Hello
world!".
• PHP strlen()
– The PHP strlen() function returns the length of a string.
– The example below returns the length of the string "Hello
world!“
<?php
echo strlen("Hello world!"); // outputs 12
?>
49.
49
• PHP Resource
•The special resource type is not an actual data
type. It is the storing of a reference to
functions and resources external to PHP.
• A common example of using the resource data
type is a database call.
50.
50
PHP Constants
• Constantsare like variables except that once they are defined
they cannot be changed or undefined.
• A constant is an identifier (name) for a simple value.
• A valid constant name starts with a letter or underscore (no $
sign before the constant name).
• Note: Unlike variables, constants are automatically global
across the entire script.
51.
51
Create a PHPConstant
• To create a constant, use the define() function.
• Syntax
define(name, value, case-insensitive)
• Parameters:
– name: Specifies the name of the constant
– value: Specifies the value of the constant
– case-insensitive: Specifies whether the constant
name should be case-insensitive. Default is false
52.
52
PHP Constants
• Theexample below creates a constant with a
case-sensitive name:
Example
<?php
define("GREETING", "Welcome to
W3Schools.com!");
echo GREETING;
?>
53.
53
PHP Constants
• Theexample below creates a constant with a
case-insensitive name:
<?php
define("GREETING", "Welcome to
W3Schools.com!", true);
echo greeting;
?>
54.
PHP Operators
• Whatis Operator?
– Simple answer can be given using expression 4 + 5 is equal to
9. Here 4 and 5 are called operands and + is called operator.
PHP language supports following type of operators.
• Operators are used to perform operations on variables and values.
• PHP divides the operators in the following groups:
– Arithmetic operators
– Assignment operators
– Comparison operators
– Increment/Decrement operators
– Logical operators
– String operators
– Array operators
55.
Arithmetic operators
Operator NameExample Result
+ Addition $x + $y Sum of $x and $y
- Subtraction $x - $y Difference of $x and $y
* Multiplication $x * $y Product of $x and $y
/ Division $x / $y Quotient of $x and $y
% Modulus $x % $y
Remainder of $x divided
by $y
**
Exponentiatio
n
$x ** $y
Result of raising $x to
the $y‘ the power
(Introduced in PHP 5.6)
56.
PHP Assignment Operators
AssignmentSame as... Description
x = y x = y
The left operand gets set to the
value of the expression on the
right
x += y x = x + y Addition
x -= y x = x - y Subtraction
x *= y x = x * y Multiplication
x /= y x = x / y Division
x %= y x = x % y Modulus
57.
PHP Comparison Operators
OperatorName Example Result
== Equal $x == $y Returns true if $x is equal to $y
=== Identical $x === $y
Returns true if $x is equal to $y, and
they are of the same type
!= Not equal $x != $y Returns true if $x is not equal to $y
<> Not equal $x <> $y Returns true if $x is not equal to $y
!== Not identical $x !== $y
Returns true if $x is not equal to $y,
or they are not of the same type
> Greater than $x > $y Returns true if $x is greater than $y
< Less than $x < $y Returns true if $x is less than $y
>=
Greater than or equal
to
$x >= $y
Returns true if $x is greater than or
equal to $y
<= Less than or equal to $x <= $y
Returns true if $x is less than or equal
to $y
58.
PHP Increment /Decrement Operators
Operator Name Description
++$x Pre-increment Increments $x by one, then returns $x
$x++
Post-
increment
Returns $x, then increments $x by one
--$x
Pre-
decrement
Decrements $x by one, then returns $x
$x--
Post-
decrement
Returns $x, then decrements $x by one
59.
PHP Logical Operators
OperatorName Example Result
and And $x and $y
True if both $x and $y are
true
or Or $x or $y
True if either $x or $y is
true
xor Xor $x xor $y
True if either $x or $y is
true, but not both
&& And $x && $y
True if both $x and $y are
true
|| Or $x || $y
True if either $x or $y is
true
! Not !$x True if $x is not true
60.
PHP String Operators
OperatorName Example Result
. Concatenation $txt1 . $txt2
Concatenation of
$txt1 and $txt2
.=
Concatenation
assignment
$txt1 .= $txt2
Appends $txt2 to
$txt1
61.
PHP Array Operators
OperatorName Example Result
+ Union $x + $y Union of $x and $y
== Equality $x == $y Returns true if $x and $y have the same key/value pairs
=== Identity $x === $y
Returns true if $x and $y have the same key/value pairs
in the same order and of the same types
!= Inequality $x != $y Returns true if $x is not equal to $y
<> Inequality $x <> $y Returns true if $x is not equal to $y
!== Non-identity $x !== $y Returns true if $x is not identical to $y
62.
Precedence of PHPOperators
Category Operator Associativity
Unary ! ++ -- Right to left
Multiplicative * / % Left to right
Additive + - Left to right
Relational < <= > >= Left to right
Equality == != Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %= Right to left
For example x = 7 + 3 * 2; Here x is assigned 13, not 20
because operator * has higher precedence than + so it first
get multiplied with 3*2 and then adds into 7.
Editor's Notes
#8 An effective website should adopt an audience-centric design. Each web site may have many different types of audience, each having a different requirement.
Logical design involves characterization of the flow of interaction
Perceptual design involves the choice of user interface widgets and the appearance of each particular page and its parts.
Content dependant on company goals in combination with the audience definition
When programming, it is useful to prototype an initial set of client-side screens using a rapid-development such as cold fusion, dreamweaver, or FrontPage and get user criticism and evaluation. This permits the screens to be changed without a great deal of effort. Once the final layout of the screens and the underlying web pages have been determined, one can proceed to code them using DHTML.