SlideShare a Scribd company logo
CN5109
WEB APPLICATION
DEVELOPMENT
Chapter 1
Introduction to Server-Side Development with PHP
What is Server-Side Development?
• The basic hosting of your files is achieved through a web
server.
• Server-side development is much more than web hosting: it
involves the use of a programming technology like PHP or ASP
to create scripts that dynamically generate content.
• Server-side scripting is a method of designing websites so
that the process or user request is run on the originating
server.
• Server-side scripts provide an interface to the user and are
used to limit access to proprietary data and help keep control
of the script source code.
What is Server-Side Development?
Server-Side Scripting Examples
• ActiveVFP
• ASP
• C
• DC
• Java
• JavaScript (using Server-side JavaScript (SSJS) e.g., node.js)
• Perl
• PHP
• Python
• R
• Ruby
Client-side vs. Server-side Scripting
Client-side Environment
• The client-side environment used to run scripts is usually a
browser.
• The processing takes place on the end users computer.
• The source code is transferred from the web server to the
users computer over the internet and run directly in the
browser.
• The scripting language needs to be enabled on the client
computer.
• Sometimes if a user is conscious of security risks they may
switch the scripting facility off.
• When this is the case a message usually pops up to alert the
user when script is attempting to run.
Client-side vs. Server-side Scripting
Server-side Environment
• The server-side environment that runs a scripting language is
a web server.
• A user's request is fulfilled by running a script directly on the
web server to generate dynamic HTML pages.
• This HTML is then sent to the client browser.
• It is usually used to provide interactive web sites that interface
to databases or other data stores on the server.
• This is different from client-side scripting where scripts are run
by the viewing web browser, usually in JavaScript.
• The primary advantage to server-side scripting is the ability to
highly customize the response based on the user's
requirements, access rights, or queries into data stores.
Client-side vs. Server-side Scripting
1. Client page request
2. Decision making
based on requested
page code content
3. HTML
output
returned to
browser
Introduction to PHP
• Created by Rasmus Lerdorf in 1994 and publicly released June
8, 1995
• PHP, which is short for PHP: Hypertext Preprocessor, is a
server-side interpreted scripting language.
• It was designed for creating dynamic web pages and web
pages that effectively work with databases.
• Files that include PHP code on a web server may have any file
extension, but most commonly they end in .PHP, .PHP3, or
.PHTML.
• A PHP file can be created and the contents can be viewed by
using a programming code editing program, such as
Dreamweaver or Notepad++.
Common Use of PHP
• 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
Advantages of 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
• PHP is free.
• PHP is easy to learn and runs efficiently on the server side
PHP - Environment Setup
• In order to develop and run PHP Web pages three vital
components need to be installed on your computer system.
• Web Server − PHP will work with virtually all Web Server
software, including Microsoft's Internet Information Server
(IIS) but then most often used is freely available Apache
Server.
• Database − PHP will work with virtually all database software,
including Oracle and Sybase but most commonly used is freely
available MySQL database.
• PHP Parser − In order to process PHP script instructions a
parser must be installed to generate HTML output that can be
sent to the Web Browser.
Quiz
1. Define Server Scripting Language
2. Give any four examples of Server Scripting Language
3. Discuss any four common use of PHP.
4. Discuss any four advantages of PHP.
PHP Installation
• To start using PHP, you can:
• Find a web host with PHP and MySQL support
• Install a web server on your own PC, and then install PHP and
MySQL
• If your server has activated support for PHP you do not need
to do anything.
• Just create some .php files, place them in your web directory,
and the server will automatically parse them for you.
• You do not need to compile anything or install any extra tools.
• Because PHP is free, most web hosts offer PHP support.
PHP Installation
• However, if your server does not support PHP, you must:
• install a web server (XAMPP, WAMP)
• install PHP
• install a database, such as MySQL
Write PHP Online
• Write PHP Online is an online code editor which helps you to
write and test run/execute your php code online from your
browser.
• This is one of the simple and powerfull online php code editor
tool available on the internet.
• Write PHP Online supports all PHP functionalities and it runs
using PHP version 7.
http://www.writephponline.com/
Write PHP Online
1. Write the PHP Code.
2. Click the “Run Code” button to see the output.
PHP Syntax
• A PHP script is executed on the server, and the plain HTML
result is sent back to the browser.
• A PHP script can be placed anywhere in the document.
• A PHP script starts with <?php and ends with ?>.
• PHP statements are terminated by a semicolon (;)
• The default file extension for PHP files is ".php".
• A PHP file normally contains HTML tags, and some PHP
scripting code.
PHP Syntax
• Example
<?php
echo "Hello World!";
?>
Output:
PHP in HTML
• PHP is designed to interact with HTML and PHP scripts can be
included in an HTML page without a problem.
• In an HTML page, PHP code is enclosed within special PHP
tags.
<html>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
HTML in PHP
• To write HTML code in PHP file, you need to use Echo or Print
statement.
<?php
echo “Hello World”;
echo “<h1> Hello World</h1>”;
?>
Output:
Echo/ Print Statement
• Used to output data to the screen.
• The echo statement can be used with or without parentheses:
echo or echo().
<?php
echo "Hello world!";
echo 123;
?>
Output:
Echo / Print Statement
• Using HTML tags in PHP:
<?php
echo “Hello”;
echo “<br>”;
echo “World”;
?>
<?php
echo “Hello <br> World”;
?>
Try This
<?php
echo "<table border=1 width=500>";
echo "<tr>";
echo "<td>1</td><td>2</td>";
echo "</tr>";
echo "<tr>";
echo "<td>3</td><td>4</td>";
echo "</tr>";
echo "</table>";
?>
Output:
Quiz
Write a PHP code to display the following outputs:
a. Welcome to FTMS College
b. University of East London
c. CN5109
Web
Application
Development
Variables
• Variables are "containers" for storing information.
• In PHP, a variable starts with the $ sign, followed by the name
of the variable
Note: When you assign a text value to a variable, put quotes
around the value.
Note: Unlike other programming languages, PHP has no
command for declaring a variable. It is created the moment you
first assign a value to it.
$txt = "Hello world!";
$x = 5;
$y = 10.5;
Variables
Rules for PHP variables:
• A variable starts with the $ sign, followed by the name of the
variable
• 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)
Quiz
Determine whether these variable names are valid or not valid.
a. text
b. $txt1
c. $1txt
d. $txt 1
e. $txt#1
f. $txt_1
Comments in PHP
• A comment in PHP code is a line that is not read/executed as
part of the program. Its only purpose is to be read by
someone who is looking at the code.
• Comments can be used to:
• Let others understand what you are doing
• Remind yourself of what you did - Most programmers
have experienced coming back to their own work a
year or two later and having to re-figure out what they
did. Comments can remind you of what you were
thinking when you wrote the code
Comments in PHP
<?php
// This is a single-line comment
# This is also a single-line comment
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
echo “This is not a comment”;
?>
Data Types
• Variables can store data of different types, and different data
types can do different things.
• Data types are declarations for variables. This determines the
type and size of data associated with variables.
• PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• NULL
Data Types - String
• A string is a sequence of characters, like "Hello world!".
• A string can be any text inside quotes.
<?php
$x = "Hello world!";
$y = “Hi There!”;
echo $x;
echo "<br>";
echo $y;
?>
Data Types - Integer
• An integer 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)
<?php
$x = 5985;
echo $x;
?>
Data Types - Float
• A float (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.
<?php
$x = 10.365;
echo $x;
?>
Data Types - Boolean
• A Boolean represents two possible states: TRUE or FALSE.
• Booleans are often used in conditional testing.
$x = true;
$y = false;
echo $x;
Data Types - Array
• An array stores multiple values in one single variable.
• In the following example $cars is an array.
<?php
$cars = array("Volvo","BMW","Toyota","Honda");
echo $cars[0],"<br>";
echo $cars[1],"<br>";
echo $cars[2],"<br>";
echo $cars[3],"<br>";
?>
Data Types - Null
• Null is a special data type which can have only one value:
NULL.
• 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 = null;
echo $x;
?>
Quiz
Identify the data type of the following data:
a. “Cyberjaya”
b. 1.35
c. 50
d. True
e. A
f. “False”
g.
h. 1, 2, 4, 8
i. “25”
Operator
• Operators are used to perform mathematical 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
Arithmetic Operators
• Arithmetic operators are used with numeric values to perform
common arithmetical operations, such as addition,
subtraction, multiplication etc.
Operation Name Example 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
Arithmetic Operators
• Example
$x = 10;
$y = 5;
echo $x + $y,"<br>";
echo $x - $y,"<br>";
echo $x * $y,"<br>";
echo $x / $y,"<br>";
echo $x % $y,"<br>";
Output:
Comparison Operators
• The PHP comparison operators are used to compare two
values (number or string).
Operator Name Example Result
== Equal $x == $y Returns true if $x is equal to $y
!= 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
>
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
Comparison Operators
• Example
$x = 10;
$y = 5;
echo $x == $y,"<br>";
echo $x <> $y,"<br>";
echo $x < $y,"<br>";
echo $x > $y,"<br>";
Output:
Increment /Decrement Operators
• Increment operators are used to increment a variable's value.
• Decrement operators are used to decrement a variable's
value.
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
Increment /Decrement Operators
• Example
$x = 10;
echo $x ,"<br>";
echo ++$x ,"<br>";
echo $x ,"<br>";
echo $x++ ,"<br>";
Output:
Logical Operators
• Example
Operator Name 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
Logical Operators
• Example
$x = 100;
$y = 50;
if ($x == 100 and $y == 50) {
echo "Hello world!";
}
Output:
Quiz
Solve the following equations:
Given $x = 10 and $y = 5
a. $x + $x + $y
b. $x - $y + $x
c. $x + $y * $x
d. $x / $y + $x
e. $x > $y
f. $y != $x
g. ++$x
h. $y--
Ad

Recommended

Os views
Os views
V.V.Vanniaperumal College for Women
 
PHP HTML CSS Notes
PHP HTML CSS Notes
Tushar Rajput
 
File access methods.54
File access methods.54
myrajendra
 
Device management
Device management
AyushiDubey19
 
JSP Processing
JSP Processing
Sadhana28
 
How the Internet Works
How the Internet Works
Sharique Masood
 
Data models
Data models
Anuj Modi
 
Transaction & Concurrency Control
Transaction & Concurrency Control
Ravimuthurajan
 
Memory virtualization
Memory virtualization
Piyush Rochwani
 
Active browser web page
Active browser web page
Zee1481
 
Loaders
Loaders
Mohd Arif
 
Introduction to Web Programming
Introduction to Web Programming
Ynon Perek
 
Presentation on web browser
Presentation on web browser
Swasat Dutta
 
Lecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptx
Amanuelmergia
 
deadlock avoidance
deadlock avoidance
wahab13
 
Dbms architecture
Dbms architecture
Shubham Dwivedi
 
Database Management System, Lecture-1
Database Management System, Lecture-1
Sonia Mim
 
Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
New Elements & Features in CSS3
New Elements & Features in CSS3
Jamshid Hashimi
 
Multimedia on the web by Sania Nisar
Multimedia on the web by Sania Nisar
Sania Nisar
 
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
sathish sak
 
3 V's of Big Data
3 V's of Big Data
sunil173422
 
Web Standards And Protocols
Web Standards And Protocols
Steven Cahill
 
Operating system deign and implementation
Operating system deign and implementation
sangrampatil81
 
String operation
String operation
Shakila Mahjabin
 
Constraints of designing for mobile devices
Constraints of designing for mobile devices
K Senthil Kumar
 
Introduction to Web Programming - first course
Introduction to Web Programming - first course
Vlad Posea
 
Operating system Deadlock
Operating system Deadlock
city university of science and information technology
 
Php unit i
Php unit i
prakashvs7
 
introduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 

More Related Content

What's hot (20)

Memory virtualization
Memory virtualization
Piyush Rochwani
 
Active browser web page
Active browser web page
Zee1481
 
Loaders
Loaders
Mohd Arif
 
Introduction to Web Programming
Introduction to Web Programming
Ynon Perek
 
Presentation on web browser
Presentation on web browser
Swasat Dutta
 
Lecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptx
Amanuelmergia
 
deadlock avoidance
deadlock avoidance
wahab13
 
Dbms architecture
Dbms architecture
Shubham Dwivedi
 
Database Management System, Lecture-1
Database Management System, Lecture-1
Sonia Mim
 
Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
New Elements & Features in CSS3
New Elements & Features in CSS3
Jamshid Hashimi
 
Multimedia on the web by Sania Nisar
Multimedia on the web by Sania Nisar
Sania Nisar
 
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
sathish sak
 
3 V's of Big Data
3 V's of Big Data
sunil173422
 
Web Standards And Protocols
Web Standards And Protocols
Steven Cahill
 
Operating system deign and implementation
Operating system deign and implementation
sangrampatil81
 
String operation
String operation
Shakila Mahjabin
 
Constraints of designing for mobile devices
Constraints of designing for mobile devices
K Senthil Kumar
 
Introduction to Web Programming - first course
Introduction to Web Programming - first course
Vlad Posea
 
Operating system Deadlock
Operating system Deadlock
city university of science and information technology
 
Active browser web page
Active browser web page
Zee1481
 
Introduction to Web Programming
Introduction to Web Programming
Ynon Perek
 
Presentation on web browser
Presentation on web browser
Swasat Dutta
 
Lecture 6- Deadlocks.pptx
Lecture 6- Deadlocks.pptx
Amanuelmergia
 
deadlock avoidance
deadlock avoidance
wahab13
 
Database Management System, Lecture-1
Database Management System, Lecture-1
Sonia Mim
 
Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 
New Elements & Features in CSS3
New Elements & Features in CSS3
Jamshid Hashimi
 
Multimedia on the web by Sania Nisar
Multimedia on the web by Sania Nisar
Sania Nisar
 
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION
sathish sak
 
3 V's of Big Data
3 V's of Big Data
sunil173422
 
Web Standards And Protocols
Web Standards And Protocols
Steven Cahill
 
Operating system deign and implementation
Operating system deign and implementation
sangrampatil81
 
Constraints of designing for mobile devices
Constraints of designing for mobile devices
K Senthil Kumar
 
Introduction to Web Programming - first course
Introduction to Web Programming - first course
Vlad Posea
 

Similar to Web Application Development using PHP Chapter 1 (20)

Php unit i
Php unit i
prakashvs7
 
introduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
Introduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
PHP - Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
PedakotaPavankumar
 
PHP ITCS 323
PHP ITCS 323
Sleepy Head
 
php 1
php 1
tumetr1
 
PHP
PHP
sometech
 
Php unit i
Php unit i
BagavathiLakshmi
 
PHP in Web development and Applications.pdf
PHP in Web development and Applications.pdf
VinayVitekari
 
PHP Hypertext Preprocessor
PHP Hypertext Preprocessor
adeel990
 
Php mysql
Php mysql
Shehrevar Davierwala
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Prersentation
Prersentation
Ashwin Deora
 
PHP Basics
PHP Basics
Roohul Amin
 
Lecture14-Introduction to PHP-coding.pdf
Lecture14-Introduction to PHP-coding.pdf
IotenergyWater
 
Introduction to PHP from Beginning to End
Introduction to PHP from Beginning to End
christopherneo4
 
Php Unit 1
Php Unit 1
team11vgnt
 
introduction to php and its uses in daily
introduction to php and its uses in daily
vishal choudhary
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
anshkhurana01
 
Introduction to PHP.pptx
Introduction to PHP.pptx
SherinRappai
 
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
PedakotaPavankumar
 
PHP in Web development and Applications.pdf
PHP in Web development and Applications.pdf
VinayVitekari
 
PHP Hypertext Preprocessor
PHP Hypertext Preprocessor
adeel990
 
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
Unit 5-PHP Declaring variables, data types, array, string, operators, Expres...
DRambabu3
 
Lecture14-Introduction to PHP-coding.pdf
Lecture14-Introduction to PHP-coding.pdf
IotenergyWater
 
Introduction to PHP from Beginning to End
Introduction to PHP from Beginning to End
christopherneo4
 
Ad

More from Mohd Harris Ahmad Jaal (20)

Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 4
Fundamentals of Programming Chapter 4
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 3
Fundamentals of Programming Chapter 3
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 2
Fundamentals of Programming Chapter 2
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 1
Fundamentals of Programming Chapter 1
Mohd Harris Ahmad Jaal
 
Fundamentals of Programming Chapter 5
Fundamentals of Programming Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 10
Fundamentals of Computing Chapter 10
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 9
Fundamentals of Computing Chapter 9
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 8
Fundamentals of Computing Chapter 8
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 7
Fundamentals of Computing Chapter 7
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 6
Fundamentals of Computing Chapter 6
Mohd Harris Ahmad Jaal
 
Fundamentals of Computing Chapter 5
Fundamentals of Computing Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 8
Web Application Development using PHP Chapter 8
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 7
Web Application Development using PHP Chapter 7
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 6
Web Application Development using PHP Chapter 6
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 5
Web Application Development using PHP Chapter 5
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 4
Web Application Development using PHP Chapter 4
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 3
Web Application Development using PHP Chapter 3
Mohd Harris Ahmad Jaal
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
Mohd Harris Ahmad Jaal
 
Ad

Recently uploaded (20)

ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
How to use _name_search() method in Odoo 18
How to use _name_search() method in Odoo 18
Celine George
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
LDMMIA Shop & Student News Summer Solstice 25
LDMMIA Shop & Student News Summer Solstice 25
LDM & Mia eStudios
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
INDUCTIVE EFFECT slide for first prof pharamacy students
INDUCTIVE EFFECT slide for first prof pharamacy students
SHABNAM FAIZ
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
How to Add New Item in CogMenu in Odoo 18
How to Add New Item in CogMenu in Odoo 18
Celine George
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
Q1_TLE 8_Week 1- Day 1 tools and equipment
Q1_TLE 8_Week 1- Day 1 tools and equipment
clairenotado3
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
ECONOMICS, DISASTER MANAGEMENT, ROAD SAFETY - STUDY MATERIAL [10TH]
SHERAZ AHMAD LONE
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
How to use _name_search() method in Odoo 18
How to use _name_search() method in Odoo 18
Celine George
 
How to use search fetch method in Odoo 18
How to use search fetch method in Odoo 18
Celine George
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
 
LDMMIA Shop & Student News Summer Solstice 25
LDMMIA Shop & Student News Summer Solstice 25
LDM & Mia eStudios
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
How payment terms are configured in Odoo 18
How payment terms are configured in Odoo 18
Celine George
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
 
Hurricane Helene Application Documents Checklists
Hurricane Helene Application Documents Checklists
Mebane Rash
 
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
 
INDUCTIVE EFFECT slide for first prof pharamacy students
INDUCTIVE EFFECT slide for first prof pharamacy students
SHABNAM FAIZ
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
How to Add New Item in CogMenu in Odoo 18
How to Add New Item in CogMenu in Odoo 18
Celine George
 
Pests of Maize: An comprehensive overview.pptx
Pests of Maize: An comprehensive overview.pptx
Arshad Shaikh
 
Q1_TLE 8_Week 1- Day 1 tools and equipment
Q1_TLE 8_Week 1- Day 1 tools and equipment
clairenotado3
 
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
SCHIZOPHRENIA OTHER PSYCHOTIC DISORDER LIKE Persistent delusion/Capgras syndr...
parmarjuli1412
 

Web Application Development using PHP Chapter 1

  • 1. CN5109 WEB APPLICATION DEVELOPMENT Chapter 1 Introduction to Server-Side Development with PHP
  • 2. What is Server-Side Development? • The basic hosting of your files is achieved through a web server. • Server-side development is much more than web hosting: it involves the use of a programming technology like PHP or ASP to create scripts that dynamically generate content. • Server-side scripting is a method of designing websites so that the process or user request is run on the originating server. • Server-side scripts provide an interface to the user and are used to limit access to proprietary data and help keep control of the script source code.
  • 3. What is Server-Side Development?
  • 4. Server-Side Scripting Examples • ActiveVFP • ASP • C • DC • Java • JavaScript (using Server-side JavaScript (SSJS) e.g., node.js) • Perl • PHP • Python • R • Ruby
  • 5. Client-side vs. Server-side Scripting Client-side Environment • The client-side environment used to run scripts is usually a browser. • The processing takes place on the end users computer. • The source code is transferred from the web server to the users computer over the internet and run directly in the browser. • The scripting language needs to be enabled on the client computer. • Sometimes if a user is conscious of security risks they may switch the scripting facility off. • When this is the case a message usually pops up to alert the user when script is attempting to run.
  • 6. Client-side vs. Server-side Scripting Server-side Environment • The server-side environment that runs a scripting language is a web server. • A user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages. • This HTML is then sent to the client browser. • It is usually used to provide interactive web sites that interface to databases or other data stores on the server. • This is different from client-side scripting where scripts are run by the viewing web browser, usually in JavaScript. • The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores.
  • 7. Client-side vs. Server-side Scripting 1. Client page request 2. Decision making based on requested page code content 3. HTML output returned to browser
  • 8. Introduction to PHP • Created by Rasmus Lerdorf in 1994 and publicly released June 8, 1995 • PHP, which is short for PHP: Hypertext Preprocessor, is a server-side interpreted scripting language. • It was designed for creating dynamic web pages and web pages that effectively work with databases. • Files that include PHP code on a web server may have any file extension, but most commonly they end in .PHP, .PHP3, or .PHTML. • A PHP file can be created and the contents can be viewed by using a programming code editing program, such as Dreamweaver or Notepad++.
  • 9. Common Use of PHP • 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
  • 10. Advantages of 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 • PHP is free. • PHP is easy to learn and runs efficiently on the server side
  • 11. PHP - Environment Setup • In order to develop and run PHP Web pages three vital components need to be installed on your computer system. • Web Server − PHP will work with virtually all Web Server software, including Microsoft's Internet Information Server (IIS) but then most often used is freely available Apache Server. • Database − PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database. • PHP Parser − In order to process PHP script instructions a parser must be installed to generate HTML output that can be sent to the Web Browser.
  • 12. Quiz 1. Define Server Scripting Language 2. Give any four examples of Server Scripting Language 3. Discuss any four common use of PHP. 4. Discuss any four advantages of PHP.
  • 13. PHP Installation • To start using PHP, you can: • Find a web host with PHP and MySQL support • Install a web server on your own PC, and then install PHP and MySQL • If your server has activated support for PHP you do not need to do anything. • Just create some .php files, place them in your web directory, and the server will automatically parse them for you. • You do not need to compile anything or install any extra tools. • Because PHP is free, most web hosts offer PHP support.
  • 14. PHP Installation • However, if your server does not support PHP, you must: • install a web server (XAMPP, WAMP) • install PHP • install a database, such as MySQL
  • 15. Write PHP Online • Write PHP Online is an online code editor which helps you to write and test run/execute your php code online from your browser. • This is one of the simple and powerfull online php code editor tool available on the internet. • Write PHP Online supports all PHP functionalities and it runs using PHP version 7. http://www.writephponline.com/
  • 16. Write PHP Online 1. Write the PHP Code. 2. Click the “Run Code” button to see the output.
  • 17. PHP Syntax • A PHP script is executed on the server, and the plain HTML result is sent back to the browser. • A PHP script can be placed anywhere in the document. • A PHP script starts with <?php and ends with ?>. • PHP statements are terminated by a semicolon (;) • The default file extension for PHP files is ".php". • A PHP file normally contains HTML tags, and some PHP scripting code.
  • 18. PHP Syntax • Example <?php echo "Hello World!"; ?> Output:
  • 19. PHP in HTML • PHP is designed to interact with HTML and PHP scripts can be included in an HTML page without a problem. • In an HTML page, PHP code is enclosed within special PHP tags. <html> <body> <?php echo "Hello World!"; ?> </body> </html>
  • 20. HTML in PHP • To write HTML code in PHP file, you need to use Echo or Print statement. <?php echo “Hello World”; echo “<h1> Hello World</h1>”; ?> Output:
  • 21. Echo/ Print Statement • Used to output data to the screen. • The echo statement can be used with or without parentheses: echo or echo(). <?php echo "Hello world!"; echo 123; ?> Output:
  • 22. Echo / Print Statement • Using HTML tags in PHP: <?php echo “Hello”; echo “<br>”; echo “World”; ?> <?php echo “Hello <br> World”; ?>
  • 23. Try This <?php echo "<table border=1 width=500>"; echo "<tr>"; echo "<td>1</td><td>2</td>"; echo "</tr>"; echo "<tr>"; echo "<td>3</td><td>4</td>"; echo "</tr>"; echo "</table>"; ?> Output:
  • 24. Quiz Write a PHP code to display the following outputs: a. Welcome to FTMS College b. University of East London c. CN5109 Web Application Development
  • 25. Variables • Variables are "containers" for storing information. • In PHP, a variable starts with the $ sign, followed by the name of the variable Note: When you assign a text value to a variable, put quotes around the value. Note: Unlike other programming languages, PHP has no command for declaring a variable. It is created the moment you first assign a value to it. $txt = "Hello world!"; $x = 5; $y = 10.5;
  • 26. Variables Rules for PHP variables: • A variable starts with the $ sign, followed by the name of the variable • 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)
  • 27. Quiz Determine whether these variable names are valid or not valid. a. text b. $txt1 c. $1txt d. $txt 1 e. $txt#1 f. $txt_1
  • 28. Comments in PHP • A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is looking at the code. • Comments can be used to: • Let others understand what you are doing • Remind yourself of what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code
  • 29. Comments in PHP <?php // This is a single-line comment # This is also a single-line comment /* This is a multiple-lines comment block that spans over multiple lines */ echo “This is not a comment”; ?>
  • 30. Data Types • Variables can store data of different types, and different data types can do different things. • Data types are declarations for variables. This determines the type and size of data associated with variables. • PHP supports the following data types: • String • Integer • Float (floating point numbers - also called double) • Boolean • Array • NULL
  • 31. Data Types - String • A string is a sequence of characters, like "Hello world!". • A string can be any text inside quotes. <?php $x = "Hello world!"; $y = “Hi There!”; echo $x; echo "<br>"; echo $y; ?>
  • 32. Data Types - Integer • An integer 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) <?php $x = 5985; echo $x; ?>
  • 33. Data Types - Float • A float (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. <?php $x = 10.365; echo $x; ?>
  • 34. Data Types - Boolean • A Boolean represents two possible states: TRUE or FALSE. • Booleans are often used in conditional testing. $x = true; $y = false; echo $x;
  • 35. Data Types - Array • An array stores multiple values in one single variable. • In the following example $cars is an array. <?php $cars = array("Volvo","BMW","Toyota","Honda"); echo $cars[0],"<br>"; echo $cars[1],"<br>"; echo $cars[2],"<br>"; echo $cars[3],"<br>"; ?>
  • 36. Data Types - Null • Null is a special data type which can have only one value: NULL. • 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 = null; echo $x; ?>
  • 37. Quiz Identify the data type of the following data: a. “Cyberjaya” b. 1.35 c. 50 d. True e. A f. “False” g. h. 1, 2, 4, 8 i. “25”
  • 38. Operator • Operators are used to perform mathematical 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
  • 39. Arithmetic Operators • Arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc. Operation Name Example 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
  • 40. Arithmetic Operators • Example $x = 10; $y = 5; echo $x + $y,"<br>"; echo $x - $y,"<br>"; echo $x * $y,"<br>"; echo $x / $y,"<br>"; echo $x % $y,"<br>"; Output:
  • 41. Comparison Operators • The PHP comparison operators are used to compare two values (number or string). Operator Name Example Result == Equal $x == $y Returns true if $x is equal to $y != 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 > 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
  • 42. Comparison Operators • Example $x = 10; $y = 5; echo $x == $y,"<br>"; echo $x <> $y,"<br>"; echo $x < $y,"<br>"; echo $x > $y,"<br>"; Output:
  • 43. Increment /Decrement Operators • Increment operators are used to increment a variable's value. • Decrement operators are used to decrement a variable's value. 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
  • 44. Increment /Decrement Operators • Example $x = 10; echo $x ,"<br>"; echo ++$x ,"<br>"; echo $x ,"<br>"; echo $x++ ,"<br>"; Output:
  • 45. Logical Operators • Example Operator Name 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
  • 46. Logical Operators • Example $x = 100; $y = 50; if ($x == 100 and $y == 50) { echo "Hello world!"; } Output:
  • 47. Quiz Solve the following equations: Given $x = 10 and $y = 5 a. $x + $x + $y b. $x - $y + $x c. $x + $y * $x d. $x / $y + $x e. $x > $y f. $y != $x g. ++$x h. $y--