SlideShare a Scribd company logo
From:
MISS AAFREEN SHAIKH (IT Teacher)
CHHATRAPATI SHIVAJI JR SCI
COLLEGE JALGAON
5. SERVER SIDE SCRIPTING (PHP)
AAFREEN SHAIKH
Index:
Features of PHP
PHP variables, datatypes
PHP Array, String function and user- defined
functions
PHP form handling
•PHP connectivity with database server
1
➢ PHP stands for Hypertext Preprocessor.
➢ It is widely used open source general purpose server- side scripting language.
➢ It is widely used for web development and can be embedded with HTML.
➢ PHP scripts are executed on the server.
➢ PHP is free to download and use.
➢ PHP runs on various platform like LINUX, UNIX, Mac OS, Windows etc.
➢ It is compatible for almost all servers used today like XAMMP, Apache, NGINX, lighttpd.
➢ It supports wide range of databases.
➢ PHP is easy to learn and runs efficiently on the server side.
➢ PHP is free to download and one can download it from the official website www.php.net
2
AAFREEN SHAIKH
3
➢ A server is a computer system that serves as a central repository of data and programs and is shared
by all clients.
➢The server side environment that runs a scripting language is termed as web server.
➢Server-side scripting as it relates to web pages usually refers to PHP code that is executed on the web
server before the data is passed to the user's browser.
➢In the case of PHP, all PHP code is executed server-side and no PHP code ever reaches the user.
➢ After the PHP code is executed, the information it outputs is embedded in the HTML, which is sent to
the viewer's web browser.
➢ It is usually used to provide interactive web sites that interfaces with databases or other data stores on
the server.
➢ Few server-side scripting languages are PHP, Java & JSP, Python.
➢PHP mainly focuses on server-side scripting , which is used to collect form data, generate dynamic page
content or send and receive cookies
AAFREEN SHAIKH
4
Simple: It is very simple and easy to use as compared to other scripting languages.
Interpreted: It is an interpreted language i.e no need of compilation.
Faster: It is faster than other scripting language e.g JSP & ASP
Open Source: It means you will not pay money to use it .You can freely download and use it.
Platform Independent: It will run on all platform like Linux, Unix, Mac OS, Windows.
Case Sensitive: It is case sensitive when you declare variables.
All keywords(echo , if, else etc) ,classes, functions and user-defined functions are not case-
sensitive.
Error Reporting: PHP has some pre-defined error reporting constants to generate a warning
or error notice.
Real Time Monitoring: PHP provides access logging by creating summary of recent accesses
for the user.
Loosely Typed Language: PHP allows you to use variable without declaring its data type. It
will be taken at the time of execution , based on the type, data has its value.
AAFREEN SHAIKH
5
• A php file normally contains HTML tags and some PHP scripting code.
• PHP Script usually enclosed in special start and end tag processing instructions.
<?php …. ?> which allows us to move into and out of php mode.
• A PHP script start with <?php and ends with ?>
Ex- <? Php
PHP program code goes here
?>
• Even it allows to embed HTML with PHP.
• Extension of php is”.php”
• PHP script can be placed anywhere in HTML document.
• echo is used to display text on web page.
AAFREEN SHAIKH
OUTPUT
6
7
8
PHP CASE SENSITIVITY
➢In PHP “Variables names ”are case sensitive.
➢However keywords(ex. If,else,break,for,while,echo), functions,
class name are not case sensitive.
➢The “ECHO” keyword is Case insensitive.
9
AAFREEN SHAIKH
Go to the browser and type http://localhost/first.php
10
First.php
AAFREEN SHAIKH
•Variable is a symbol or name that stands for a value.
•Variables are used for storing values such as numeric, characters, strings or
memory addresses, so that they can be used in any part of program.
RULES FOR DECLARING VARIABLES
•Variable starts with $ sign, followed by name of the variable.
•A variable name must start with a letter or 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 _[underscore]) .
•Variable names are case-sensitive. (Eg. $age and $AGE are considered different).
11
AAFREEN SHAIKH
🞂 Program using PHP
variables
12
<!DOCTYPE html>
<html>
<body>
<?php
$txt = "Hello world!";
$x = 5;
echo $txt;
echo "<br>";
echo $x;
?>
</body>
</html>
OUTPUT
Hello world!
5
AAFREEN SHAIKH
SCOPE OF VARIABLES IN PHP
•Local: A variable declared within a function has local scope and can be accessed
within that function.
• Global: A variable declared outside the function has a global scope and can only
be accessed outside the function.
•Static: When a function is executed , then all of its variables are deleted. If you
want a local variable not to be deleted then use must use static keyword.
Comments
Comments :-are not visible in the output of the program as it is ignored during
the execution.
A single line comments is given by // or # before the PHP statement and a
multi-line comment is possible by /*…*/
13
AAFREEN SHAIKH
14
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
PHP DATA TYPES
PHP can store data of different types and PHP supports following data types:
•String
•Integer
•Float
•Boolean
•Array
•NULL
•One can check the data_type of variable using var_dump() method in PHP.
•var_dump() gives different output for each data_type.
➢It gives length of the string for “string”
data_type.
➢It gives actual value of integer for “integer”
data_type.
➢It gives true/false for “boolean” data_type
15
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
CONTROL STRUCTURES IN PHP
If STATEMENT : if STATEMENT ALLOWS PROGRAMMER to MAKE decision, BASED on one or
more conditions; AND execute A piece of code CONDITIONALLY.
SYNTAX :
if(condition)
{
block of statement;
}
2. If-else statement: if-else statement allows programmer to make decision based
on either this or that conditions.
Syntax: if(condition)
{
statement;
}
else
{
statement
}
16
AAFREEN SHAIKH
CONTROL STRUCTURES IN PHP
<!DOCTYPE html>
<html>
<body>
<?php
$t=10;
if ($t < "20")
{
echo "LESS THAN 20 !";
}
?>
</body>
</html>
OUTPUT
LESS THAN 20 !
17
IF - ELSE
SIMPLE IF
AAFREEN SHAIKH
and loop iteration (increment or decrement) in single
combines initialization, condition
statement.
Syntax :
for(initialisation;condition;increment/decrement)
{
Statement;
}
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
for…….loop
Loops are used to execute the same block of code repeatedly as long as a certain condition is
satisfied.
This loop executes statements as long as condition becomes true, for-loop is that it
code to be executed
18
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
foreach…….loop
foreach loop: This loop work only on arrays, and is used to loop through each key/value pair in
array. For every loop iteration, the value of the current array element is assigned to
$value and the array pointer is moved by one, until it reaches the last array element.
NOTE: (.) is used for concatenation purp
Syntax: foreach($array as $value)
{
code to be executed;
}
ose.
Output
19
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
foreach…….loop
Output
<?php
$array1 = array(1, 2, 3, 4, 6, 22, 32, 12, 11, 14, 16, 17, 18, 19, 28);
foreach ($array1 as $value1) {
$value1 = $value1 * 2;
echo $value1.", ";
}
?>
20
AAFREEN SHAIKH
21
AAFREEN SHAIKH
PHP STRING FUNCTION
•A string is series of character.
•The real power of PHP comes from its functions.
•A function is block of statement used repeatedly in a program.
•PHP has many built-in functions which can be called directly to perform a
specific task.
22
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
PHP ARRAY
• An array is a special variable which can hold more than a value at a time.
•An array stores multiple values in one single variable.
• The index can be assigned automatically.(index always starts with 0)
Syntax: $array_name=array(value1,value2,……., value n)
$cars
= array("Volvo", "BMW", "Toyota");
$cars[0]= Volvo
$cars[1]= BMW
$cars[2]= Toyota
• There are 3 types of arrays
•Indexed arrays - Arrays with a numeric index
•Associative arrays - Arrays with named keys
•Multidimensional arrays - Arrays containing one or more arrays
23
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
➢In this example , we store subject is an
array at following index location.
$subject[0]=“English”
$subject[1]=“Hindi”
$subject[2]=“Marathi”
count() function is used to return the Length of
24
array
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
•A function is block of statement used repeatedly in a program.
•It will not execute immediately when a page loads but will be executed by a
call to the function.
•Along with built-in PHP functions we can create our own functions.
•User-defined function starts with the word function.
• Information can be passed to functions through arguments.
•An argument is just a variable.
•Arguments are specified after the function name, inside brackets.
Syntax: function fun_name()
{
code to be executed
}
25
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
26
AAFREEN SHAIKH
Note : 'language' attribute of <Script> is replaced by 'type' attribute in all the programs as it is standardized.
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
Use return statement to return a value.
27
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
PHP ASSOCIATIVE ARRAYS :
ASSOCIATIVE ARRAYS ARE ARRAYS THAT use NAMED keys INSTEAD of index to
identify RECORD/VALUE.
Let us see how to CREATE ASSOCIATIVE ARRAY.
SYNTAX :
$a = array( key1 => value1, key2=>value2, ...,key n => value n)
VALUES of ‘STUDENT_MARK’ ARRAY ARE
stored in following WAY:
28
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
When to use GET?
➢Information send from a form using GET method is visible to everyone.(names
and values of variables are displayed on URL)
➢ It also has limit on amount of information to send. Because the variables are
displayed in the URL ,it is possible to bookmark the page.
➢It may be used to send some non-sensitive data.
➢ It should never be used to for sending passwords or other sensitive
information.
29
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
Let us see one program on “get” method
30
AAFREEN SHAIKH
31
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
When to use POST?
➢Information send from a form using POST method is invisible to
everyone.(all names and values are embedded within the body of the
HTTP request.)
➢ It has no limit on amount of information to send.
➢Moreover POST supports advanced functionality such as support
for multi-part binary input while uploading files to the server.
➢ The variables are not passed in the URL so it is possible to
bookmark the page.
32
AAFREEN SHAIKH
Note : 'language' attribute of <Script> is replaced by 'type' attribute in all the programs as it is standardized.
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
A simple HTML form with 2 input fields and submit button code is as
follows:
33
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
➢When user fills out the form above and clicks
the submit button , the form data is sent for
processing to a PHP file names “welcome
.php”.
➢The form data is sent with the HTTP POST
method.
34
➢ The code for “welcome.php” looks like this
AAFREEN SHAIKH
•Both GET and POST are treated as $_GET and $_POST super globals,
which means they are accessible ,regardless of scope.
•It can be accessed from function ,class or file without having to do
anything special.
•$_GET is an array of variables passed via the URL parameters.
•$_POST is an array of variables passed via the HTTP POST method.
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
GET vs POST
35
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
Summary
PHP is widely-used open source server-side programming language which runs on
various platforms.
PHP is a script executed on server which generate dynamic HTML pages.
The PHP code can also be embedded with HTML tags using <?php and ?>.
PHP is case sensitive only at time of variable declaration and not-case sensitive for
other keywords.
PHP variable start with $ sign followed by name of variable which must start with a
alpha-numeric characters or underscore character.
PHP variable has three different scopes namely : local, global and static.
PHP supports String, Integer, Float, Boolean, Array and NULL data types.
Three types of Arrays are Indexed array, Associative array and Multi-dimensional
array.
PHP supports ‘foreach’ loop to iterate easily.
String functions are used to manipulate strings.
36
AAFREEN SHAIKH
PIMPRI CHINCHWAD EDUCATION TRUST’S
S.B.PATIL COLLEGE OF
Science and Commerce, Ravet
Summary
A function is a block of statements that can be used repeatedly in a program.
Information can be passed to functions through arguments.
Form is used to collect information from user and process or store in database.
Form data can be submitted by GET or POST method.
The PHP superglobals $_GET and $_POST are used to collect form-data.
$_GET is an array of variables passed via the URL parameters and are visible to
everyone.
$_POST is an array of variables passed via the HTTP POST method and are
invisible to others.
GET has limits on the amount of information to send whereas POST has no limits
on the amount of information to send.
GET should NEVER be used for sending sensitive information.
Cookies are sent along when browser requests server pages.
Session helps web application to maintain user information on all the pages.
37
AAFREEN SHAIKH
Thank you !
38

More Related Content

PDF
Hsc IT 5. Server-Side Scripting (PHP).pdf
PDF
Php tutorial from_beginner_to_master
PPTX
Php Tutorial
PDF
Materi Dasar PHP
PPTX
introduction to php and its uses in daily
PDF
Php tutorial(w3schools)
PDF
Php tutorialw3schools
PPT
PHP - Introduction to PHP Fundamentals
Hsc IT 5. Server-Side Scripting (PHP).pdf
Php tutorial from_beginner_to_master
Php Tutorial
Materi Dasar PHP
introduction to php and its uses in daily
Php tutorial(w3schools)
Php tutorialw3schools
PHP - Introduction to PHP Fundamentals

Similar to Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP (20)

PDF
Php notes
PDF
1336333055 php tutorial_from_beginner_to_master
PPTX
Server Scripting Language -PHP
PDF
Introduction to php
PPTX
Basic of PHP
PPTX
PPT 19.pptx
PPTX
PHP from soup to nuts Course Deck
PPT
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
PPTX
PPSX
PPTX
php Chapter 1.pptx
PPT
PHP MySQL Workshop - facehook
PDF
PHP Basic & Variables
PPTX
Php and MySQL final year bca notes for bca.pptx
PDF
Php introduction
PDF
Chap 4 PHP.pdf
PPT
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
PPT
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php notes
1336333055 php tutorial_from_beginner_to_master
Server Scripting Language -PHP
Introduction to php
Basic of PHP
PPT 19.pptx
PHP from soup to nuts Course Deck
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
php Chapter 1.pptx
PHP MySQL Workshop - facehook
PHP Basic & Variables
Php and MySQL final year bca notes for bca.pptx
Php introduction
Chap 4 PHP.pdf
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Ad

More from AAFREEN SHAIKH (20)

PDF
3-inheritanc-and-variation.pdf HSC BIOLOGY 3-inheritanc-and-variation
PDF
1-reproduction-in-plants-assignment-notes.pdf
PDF
Rotational-Dynamics-ppt3.pdf HSC PHYSICS CHAPTER 1 ROTATIONAL DYNAMIC PART 3
PDF
Rotational-Dynamics-ppt2.pdf HSC PHYSICS CHAPTER 1 Rotational-Dynamics PART-2
PDF
Rotational-Dynamics-ppt1.pdf HSC PHYSICS CHAPTER 1 Rotational-Dynamics PART-1
PDF
assesment-12th BY AAFREEN SHAIKH.pdf HSC assesment
PDF
English-Paper-Pattern.pdf HSC ENGLISH PAPER PATTERN
PDF
Lesson-6-Ecommerce-&-EGovernance BY AAFREEN SHAIKH.pdf
PDF
Lesson-4-Emerging-Technology BY AAFREEN SHAIKH.pdf
DOCX
Std.-XI-Unit-Test-No.-1-Third-Practice-Test-By-Prof.-Aafreen Shaikh.docx
PDF
Std.-XI-Unit-Test-2-By-Prof.-aafreen shaikh.pdf
PDF
Std.-XI-Unit-Test-No.1-For-First-Term-By-Prof.-Aafreen Shaikh.pdf
PDF
GEOGRAPHY QUESTION PAPER.pdf HSC GEOGRAPHY QUESTION PAPER
PDF
CHEMISTRY QUESTION PAPERS.pdf HSC CHEMISTRY QUESTION PAPERS
PDF
marathi question paper.pdf hsc marathi prelims sample question papers
PDF
Ls-No-1 Web Publishing Notes.pdf 12th information technology chapter 1
PDF
Solutions - formula sheet.pdf 12TH IMPORTANT FORMULA SHEET CHAP 3 CHEMISTRY
PDF
Some basic Concepts of Chemistry.pdf class 11th science chemistry chapter 1 s...
PPT
HTML NOTES.ppt BASIC HTML PROGRAMING NOTES
PDF
UNIT4.pdf php basic programming for begginers
3-inheritanc-and-variation.pdf HSC BIOLOGY 3-inheritanc-and-variation
1-reproduction-in-plants-assignment-notes.pdf
Rotational-Dynamics-ppt3.pdf HSC PHYSICS CHAPTER 1 ROTATIONAL DYNAMIC PART 3
Rotational-Dynamics-ppt2.pdf HSC PHYSICS CHAPTER 1 Rotational-Dynamics PART-2
Rotational-Dynamics-ppt1.pdf HSC PHYSICS CHAPTER 1 Rotational-Dynamics PART-1
assesment-12th BY AAFREEN SHAIKH.pdf HSC assesment
English-Paper-Pattern.pdf HSC ENGLISH PAPER PATTERN
Lesson-6-Ecommerce-&-EGovernance BY AAFREEN SHAIKH.pdf
Lesson-4-Emerging-Technology BY AAFREEN SHAIKH.pdf
Std.-XI-Unit-Test-No.-1-Third-Practice-Test-By-Prof.-Aafreen Shaikh.docx
Std.-XI-Unit-Test-2-By-Prof.-aafreen shaikh.pdf
Std.-XI-Unit-Test-No.1-For-First-Term-By-Prof.-Aafreen Shaikh.pdf
GEOGRAPHY QUESTION PAPER.pdf HSC GEOGRAPHY QUESTION PAPER
CHEMISTRY QUESTION PAPERS.pdf HSC CHEMISTRY QUESTION PAPERS
marathi question paper.pdf hsc marathi prelims sample question papers
Ls-No-1 Web Publishing Notes.pdf 12th information technology chapter 1
Solutions - formula sheet.pdf 12TH IMPORTANT FORMULA SHEET CHAP 3 CHEMISTRY
Some basic Concepts of Chemistry.pdf class 11th science chemistry chapter 1 s...
HTML NOTES.ppt BASIC HTML PROGRAMING NOTES
UNIT4.pdf php basic programming for begginers
Ad

Recently uploaded (20)

PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Classroom Observation Tools for Teachers
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Institutional Correction lecture only . . .
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
master seminar digital applications in india
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPH.pptx obstetrics and gynecology in nursing
Classroom Observation Tools for Teachers
Microbial diseases, their pathogenesis and prophylaxis
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Computing-Curriculum for Schools in Ghana
Institutional Correction lecture only . . .
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Complications of Minimal Access Surgery at WLH
O7-L3 Supply Chain Operations - ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Renaissance Architecture: A Journey from Faith to Humanism
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Pharma ospi slides which help in ospi learning
Anesthesia in Laparoscopic Surgery in India
Sports Quiz easy sports quiz sports quiz
master seminar digital applications in india
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
102 student loan defaulters named and shamed – Is someone you know on the list?

Lesson-5-php BY AAFREEN SHAIKH.pdf HSC INFORMATION TECHNOLOGY CHAP 5 PHP

  • 1. From: MISS AAFREEN SHAIKH (IT Teacher) CHHATRAPATI SHIVAJI JR SCI COLLEGE JALGAON 5. SERVER SIDE SCRIPTING (PHP) AAFREEN SHAIKH Index: Features of PHP PHP variables, datatypes PHP Array, String function and user- defined functions PHP form handling •PHP connectivity with database server 1
  • 2. ➢ PHP stands for Hypertext Preprocessor. ➢ It is widely used open source general purpose server- side scripting language. ➢ It is widely used for web development and can be embedded with HTML. ➢ PHP scripts are executed on the server. ➢ PHP is free to download and use. ➢ PHP runs on various platform like LINUX, UNIX, Mac OS, Windows etc. ➢ It is compatible for almost all servers used today like XAMMP, Apache, NGINX, lighttpd. ➢ It supports wide range of databases. ➢ PHP is easy to learn and runs efficiently on the server side. ➢ PHP is free to download and one can download it from the official website www.php.net 2 AAFREEN SHAIKH
  • 3. 3 ➢ A server is a computer system that serves as a central repository of data and programs and is shared by all clients. ➢The server side environment that runs a scripting language is termed as web server. ➢Server-side scripting as it relates to web pages usually refers to PHP code that is executed on the web server before the data is passed to the user's browser. ➢In the case of PHP, all PHP code is executed server-side and no PHP code ever reaches the user. ➢ After the PHP code is executed, the information it outputs is embedded in the HTML, which is sent to the viewer's web browser. ➢ It is usually used to provide interactive web sites that interfaces with databases or other data stores on the server. ➢ Few server-side scripting languages are PHP, Java & JSP, Python. ➢PHP mainly focuses on server-side scripting , which is used to collect form data, generate dynamic page content or send and receive cookies AAFREEN SHAIKH
  • 4. 4 Simple: It is very simple and easy to use as compared to other scripting languages. Interpreted: It is an interpreted language i.e no need of compilation. Faster: It is faster than other scripting language e.g JSP & ASP Open Source: It means you will not pay money to use it .You can freely download and use it. Platform Independent: It will run on all platform like Linux, Unix, Mac OS, Windows. Case Sensitive: It is case sensitive when you declare variables. All keywords(echo , if, else etc) ,classes, functions and user-defined functions are not case- sensitive. Error Reporting: PHP has some pre-defined error reporting constants to generate a warning or error notice. Real Time Monitoring: PHP provides access logging by creating summary of recent accesses for the user. Loosely Typed Language: PHP allows you to use variable without declaring its data type. It will be taken at the time of execution , based on the type, data has its value. AAFREEN SHAIKH
  • 5. 5 • A php file normally contains HTML tags and some PHP scripting code. • PHP Script usually enclosed in special start and end tag processing instructions. <?php …. ?> which allows us to move into and out of php mode. • A PHP script start with <?php and ends with ?> Ex- <? Php PHP program code goes here ?> • Even it allows to embed HTML with PHP. • Extension of php is”.php” • PHP script can be placed anywhere in HTML document. • echo is used to display text on web page. AAFREEN SHAIKH
  • 7. 7
  • 8. 8
  • 9. PHP CASE SENSITIVITY ➢In PHP “Variables names ”are case sensitive. ➢However keywords(ex. If,else,break,for,while,echo), functions, class name are not case sensitive. ➢The “ECHO” keyword is Case insensitive. 9 AAFREEN SHAIKH
  • 10. Go to the browser and type http://localhost/first.php 10 First.php AAFREEN SHAIKH
  • 11. •Variable is a symbol or name that stands for a value. •Variables are used for storing values such as numeric, characters, strings or memory addresses, so that they can be used in any part of program. RULES FOR DECLARING VARIABLES •Variable starts with $ sign, followed by name of the variable. •A variable name must start with a letter or 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 _[underscore]) . •Variable names are case-sensitive. (Eg. $age and $AGE are considered different). 11 AAFREEN SHAIKH
  • 12. 🞂 Program using PHP variables 12 <!DOCTYPE html> <html> <body> <?php $txt = "Hello world!"; $x = 5; echo $txt; echo "<br>"; echo $x; ?> </body> </html> OUTPUT Hello world! 5 AAFREEN SHAIKH
  • 13. SCOPE OF VARIABLES IN PHP •Local: A variable declared within a function has local scope and can be accessed within that function. • Global: A variable declared outside the function has a global scope and can only be accessed outside the function. •Static: When a function is executed , then all of its variables are deleted. If you want a local variable not to be deleted then use must use static keyword. Comments Comments :-are not visible in the output of the program as it is ignored during the execution. A single line comments is given by // or # before the PHP statement and a multi-line comment is possible by /*…*/ 13 AAFREEN SHAIKH
  • 15. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet PHP DATA TYPES PHP can store data of different types and PHP supports following data types: •String •Integer •Float •Boolean •Array •NULL •One can check the data_type of variable using var_dump() method in PHP. •var_dump() gives different output for each data_type. ➢It gives length of the string for “string” data_type. ➢It gives actual value of integer for “integer” data_type. ➢It gives true/false for “boolean” data_type 15 AAFREEN SHAIKH
  • 16. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet CONTROL STRUCTURES IN PHP If STATEMENT : if STATEMENT ALLOWS PROGRAMMER to MAKE decision, BASED on one or more conditions; AND execute A piece of code CONDITIONALLY. SYNTAX : if(condition) { block of statement; } 2. If-else statement: if-else statement allows programmer to make decision based on either this or that conditions. Syntax: if(condition) { statement; } else { statement } 16 AAFREEN SHAIKH
  • 17. CONTROL STRUCTURES IN PHP <!DOCTYPE html> <html> <body> <?php $t=10; if ($t < "20") { echo "LESS THAN 20 !"; } ?> </body> </html> OUTPUT LESS THAN 20 ! 17 IF - ELSE SIMPLE IF AAFREEN SHAIKH
  • 18. and loop iteration (increment or decrement) in single combines initialization, condition statement. Syntax : for(initialisation;condition;increment/decrement) { Statement; } PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet for…….loop Loops are used to execute the same block of code repeatedly as long as a certain condition is satisfied. This loop executes statements as long as condition becomes true, for-loop is that it code to be executed 18 AAFREEN SHAIKH
  • 19. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet foreach…….loop foreach loop: This loop work only on arrays, and is used to loop through each key/value pair in array. For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element. NOTE: (.) is used for concatenation purp Syntax: foreach($array as $value) { code to be executed; } ose. Output 19 AAFREEN SHAIKH
  • 20. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet foreach…….loop Output <?php $array1 = array(1, 2, 3, 4, 6, 22, 32, 12, 11, 14, 16, 17, 18, 19, 28); foreach ($array1 as $value1) { $value1 = $value1 * 2; echo $value1.", "; } ?> 20 AAFREEN SHAIKH
  • 22. PHP STRING FUNCTION •A string is series of character. •The real power of PHP comes from its functions. •A function is block of statement used repeatedly in a program. •PHP has many built-in functions which can be called directly to perform a specific task. 22 AAFREEN SHAIKH
  • 23. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet PHP ARRAY • An array is a special variable which can hold more than a value at a time. •An array stores multiple values in one single variable. • The index can be assigned automatically.(index always starts with 0) Syntax: $array_name=array(value1,value2,……., value n) $cars = array("Volvo", "BMW", "Toyota"); $cars[0]= Volvo $cars[1]= BMW $cars[2]= Toyota • There are 3 types of arrays •Indexed arrays - Arrays with a numeric index •Associative arrays - Arrays with named keys •Multidimensional arrays - Arrays containing one or more arrays 23 AAFREEN SHAIKH
  • 24. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet ➢In this example , we store subject is an array at following index location. $subject[0]=“English” $subject[1]=“Hindi” $subject[2]=“Marathi” count() function is used to return the Length of 24 array AAFREEN SHAIKH
  • 25. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet •A function is block of statement used repeatedly in a program. •It will not execute immediately when a page loads but will be executed by a call to the function. •Along with built-in PHP functions we can create our own functions. •User-defined function starts with the word function. • Information can be passed to functions through arguments. •An argument is just a variable. •Arguments are specified after the function name, inside brackets. Syntax: function fun_name() { code to be executed } 25 AAFREEN SHAIKH
  • 26. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet 26 AAFREEN SHAIKH
  • 27. Note : 'language' attribute of <Script> is replaced by 'type' attribute in all the programs as it is standardized. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet Use return statement to return a value. 27 AAFREEN SHAIKH
  • 28. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet PHP ASSOCIATIVE ARRAYS : ASSOCIATIVE ARRAYS ARE ARRAYS THAT use NAMED keys INSTEAD of index to identify RECORD/VALUE. Let us see how to CREATE ASSOCIATIVE ARRAY. SYNTAX : $a = array( key1 => value1, key2=>value2, ...,key n => value n) VALUES of ‘STUDENT_MARK’ ARRAY ARE stored in following WAY: 28 AAFREEN SHAIKH
  • 29. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet When to use GET? ➢Information send from a form using GET method is visible to everyone.(names and values of variables are displayed on URL) ➢ It also has limit on amount of information to send. Because the variables are displayed in the URL ,it is possible to bookmark the page. ➢It may be used to send some non-sensitive data. ➢ It should never be used to for sending passwords or other sensitive information. 29 AAFREEN SHAIKH
  • 30. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet Let us see one program on “get” method 30 AAFREEN SHAIKH
  • 32. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet When to use POST? ➢Information send from a form using POST method is invisible to everyone.(all names and values are embedded within the body of the HTTP request.) ➢ It has no limit on amount of information to send. ➢Moreover POST supports advanced functionality such as support for multi-part binary input while uploading files to the server. ➢ The variables are not passed in the URL so it is possible to bookmark the page. 32 AAFREEN SHAIKH
  • 33. Note : 'language' attribute of <Script> is replaced by 'type' attribute in all the programs as it is standardized. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet A simple HTML form with 2 input fields and submit button code is as follows: 33 AAFREEN SHAIKH
  • 34. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet ➢When user fills out the form above and clicks the submit button , the form data is sent for processing to a PHP file names “welcome .php”. ➢The form data is sent with the HTTP POST method. 34 ➢ The code for “welcome.php” looks like this AAFREEN SHAIKH
  • 35. •Both GET and POST are treated as $_GET and $_POST super globals, which means they are accessible ,regardless of scope. •It can be accessed from function ,class or file without having to do anything special. •$_GET is an array of variables passed via the URL parameters. •$_POST is an array of variables passed via the HTTP POST method. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet GET vs POST 35 AAFREEN SHAIKH
  • 36. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet Summary PHP is widely-used open source server-side programming language which runs on various platforms. PHP is a script executed on server which generate dynamic HTML pages. The PHP code can also be embedded with HTML tags using <?php and ?>. PHP is case sensitive only at time of variable declaration and not-case sensitive for other keywords. PHP variable start with $ sign followed by name of variable which must start with a alpha-numeric characters or underscore character. PHP variable has three different scopes namely : local, global and static. PHP supports String, Integer, Float, Boolean, Array and NULL data types. Three types of Arrays are Indexed array, Associative array and Multi-dimensional array. PHP supports ‘foreach’ loop to iterate easily. String functions are used to manipulate strings. 36 AAFREEN SHAIKH
  • 37. PIMPRI CHINCHWAD EDUCATION TRUST’S S.B.PATIL COLLEGE OF Science and Commerce, Ravet Summary A function is a block of statements that can be used repeatedly in a program. Information can be passed to functions through arguments. Form is used to collect information from user and process or store in database. Form data can be submitted by GET or POST method. The PHP superglobals $_GET and $_POST are used to collect form-data. $_GET is an array of variables passed via the URL parameters and are visible to everyone. $_POST is an array of variables passed via the HTTP POST method and are invisible to others. GET has limits on the amount of information to send whereas POST has no limits on the amount of information to send. GET should NEVER be used for sending sensitive information. Cookies are sent along when browser requests server pages. Session helps web application to maintain user information on all the pages. 37 AAFREEN SHAIKH