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--

More Related Content

PPTX
Laravel ppt
Mayank Panchal
 
PPTX
Laravel introduction
Simon Funk
 
PPTX
Php.ppt
Nidhi mishra
 
PPTX
laravel.pptx
asif290119
 
PPTX
Avro introduction
Nanda8904648951
 
PPTX
Wordpress ppt
Crest TechnoSoft
 
PPTX
Web Development
Aditya Raman
 
PDF
Web application development with laravel php framework version 4
Untung D Saptoto
 
Laravel ppt
Mayank Panchal
 
Laravel introduction
Simon Funk
 
Php.ppt
Nidhi mishra
 
laravel.pptx
asif290119
 
Avro introduction
Nanda8904648951
 
Wordpress ppt
Crest TechnoSoft
 
Web Development
Aditya Raman
 
Web application development with laravel php framework version 4
Untung D Saptoto
 

What's hot (20)

PPTX
Introduction to MERN
ShyamMohanKunwar
 
PPTX
Laravel Presentation
REZAUL KARIM REFATH
 
PPT
RMI
Aravind Nair
 
PPTX
Introduction to laravel framework
Ahmad Fatoni
 
DOCX
Odi interview questions
Udaykumar Sarana
 
PPTX
Php basics
Jamshid Hashimi
 
PPTX
Hibernate ppt
Aneega
 
PPTX
Laravel overview
Obinna Akunne
 
PPT
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
PPTX
Message queue architecture
Majdee Zoabi
 
PPTX
Ruby programming
Kartik Kalpande Patil
 
PPTX
Une introduction à Javascript et ECMAScript 6
Jean-Baptiste Vigneron
 
PDF
Configuring the Apache Web Server
webhostingguy
 
PDF
Introduction to Ruby
kim.mens
 
PDF
Nodejs presentation
Arvind Devaraj
 
PPTX
Php technical presentation
dharmendra kumar dhakar
 
PPT
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
PPTX
Introduction to spring boot
Santosh Kumar Kar
 
PPT
An Introduction To Java Web Technology
vikram singh
 
Introduction to MERN
ShyamMohanKunwar
 
Laravel Presentation
REZAUL KARIM REFATH
 
Introduction to laravel framework
Ahmad Fatoni
 
Odi interview questions
Udaykumar Sarana
 
Php basics
Jamshid Hashimi
 
Hibernate ppt
Aneega
 
Laravel overview
Obinna Akunne
 
PHP - DataType,Variable,Constant,Operators,Array,Include and require
TheCreativedev Blog
 
Message queue architecture
Majdee Zoabi
 
Ruby programming
Kartik Kalpande Patil
 
Une introduction à Javascript et ECMAScript 6
Jean-Baptiste Vigneron
 
Configuring the Apache Web Server
webhostingguy
 
Introduction to Ruby
kim.mens
 
Nodejs presentation
Arvind Devaraj
 
Php technical presentation
dharmendra kumar dhakar
 
PHP complete reference with database concepts for beginners
Mohammed Mushtaq Ahmed
 
Introduction to spring boot
Santosh Kumar Kar
 
An Introduction To Java Web Technology
vikram singh
 
Ad

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

PPTX
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
PedakotaPavankumar
 
PPTX
Php unit i
BagavathiLakshmi
 
PPTX
Introduction to PHP.pptx
MarianJRuben
 
PPTX
Php intro
sana mateen
 
PPTX
introduction to php and its uses in daily
vishal choudhary
 
PPTX
1. introduction to php and variable
NurAliaAqilaMuhalis
 
PPT
Introduction to php
Meetendra Singh
 
PPTX
Php reports sumit
Sumit Biswas
 
PPTX
Introduction to PHP.pptx
SherinRappai
 
PPTX
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
PRIYADARSINIK3
 
PPTX
php Chapter 1.pptx
HambaAbebe2
 
PPTX
php basic part one
jeweltutin
 
PPT
Php unit i
prakashvs7
 
PPT
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
PDF
Materi Dasar PHP
Robby Firmansyah
 
PPT
introduction to php notes for engineering students.ppt
manju451965
 
PDF
waptLab 04.pdfwaptLab09 tis lab is used for college lab exam
imgautam076
 
PPTX
PHP ITCS 323
Sleepy Head
 
PPT
Php
Ajay Kumar
 
lec1 (1).pptxkeoiwjwoijeoiwjeoijwoeijewoi
PedakotaPavankumar
 
Php unit i
BagavathiLakshmi
 
Introduction to PHP.pptx
MarianJRuben
 
Php intro
sana mateen
 
introduction to php and its uses in daily
vishal choudhary
 
1. introduction to php and variable
NurAliaAqilaMuhalis
 
Introduction to php
Meetendra Singh
 
Php reports sumit
Sumit Biswas
 
Introduction to PHP.pptx
SherinRappai
 
INTRODUCTION ON PHP - SERVER SIDE SCRIPTING LANGUAGE
PRIYADARSINIK3
 
php Chapter 1.pptx
HambaAbebe2
 
php basic part one
jeweltutin
 
Php unit i
prakashvs7
 
PHP MySQL Workshop - facehook
Shashank Skills Academy
 
Materi Dasar PHP
Robby Firmansyah
 
introduction to php notes for engineering students.ppt
manju451965
 
waptLab 04.pdfwaptLab09 tis lab is used for college lab exam
imgautam076
 
PHP ITCS 323
Sleepy Head
 
Ad

More from Mohd Harris Ahmad Jaal (20)

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

Recently uploaded (20)

PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
Trends in pediatric nursing .pptx
AneetaSharma15
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
PPTX
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Trends in pediatric nursing .pptx
AneetaSharma15
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
FSSAI (Food Safety and Standards Authority of India) & FDA (Food and Drug Adm...
Dr. Paindla Jyothirmai
 
Software Engineering BSC DS UNIT 1 .pptx
Dr. Pallawi Bulakh
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
CDH. pptx
AneetaSharma15
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 

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--