SlideShare a Scribd company logo
NAME OF STAFF :S.SAYI PRIYA
NAME OF STUDENT : J.THEORITA
REGISTER NUMBER :CB17S 250447
CLASS :III-BCA-B
BATCH :2017-2020
YEAR :2020
SUBJECT CODE :MCA511
INTRODUCTION IN PHP
PHP started out as a small open source project that evolved as
more and more people found out how useful it was. Rasmus
Lerdorf unleashed the first version of PHP way back in 1994.
PHP is a recursive acronym for "PHP: Hypertext Preprocessor".
PHP is a server side scripting language that is embedded in
HTML. It is used to manage dynamic content, databases, session
tracking, even build entire e-commerce sites.
It is integrated with a number of popular databases,
including MySQL, PostgreSQL, Oracle, Sybase,
Informix, and Microsoft SQL Server.
PHP is pleasingly zippy in its execution, especially when
compiled as an Apache module on the Unix side. The
MySQL server, once started, executes even very complex
queries with huge result sets in record-setting time
PHP supports a large number of major protocols such as
POP3, IMAP, and LDAP. PHP4 added support for Java
and distributed object architectures (COM and CORBA),
making n-tier development a possibility for the first time
PHP is forgiving: PHP language tries to be as forgiving as
possible.
PHP Syntax is C-Like
Characteristics of PHP:
o Five important characteristics make PHP's practical nature
possible:
 Simplicity
Efficiency
Security
Flexibility
Familiarity
PHP ─ VARIABLE TYPES
 The main way to store information in the middle of a PHP
program is by using a variable. Here are the most important
things to know about variables in PHP.
 All variables in PHP are denoted with a leading dollar sign ($).
 The value of a variable is the value of its most recent
assignment.
 Variables are assigned with the = operator, with the variable on
the left-hand side and the expression to be evaluated on the right.
 Variables can, but do not need, to be declared before assignment.
 Variables in PHP do not have intrinsic types - a variable does not
know in advance whether it will be used to store a number or a
string of characters.
PHP has a total of eight data types which we use to construct our
variables:
o Integers: are whole numbers, without a decimal point, like 4195.
o Doubles: are floating-point numbers, like 3.14159 or 49.1.
o Booleans: have only two possible values either true or false.
o NULL: is a special type that only has one value: NULL.
o Strings: are sequences of characters, like 'PHP supports string
operations.'
o Arrays: are named and indexed collections of other values.
o Objects: are instances of programmer-defined classes, which can
package up both other kinds of values and functions that are specific to
the class.
o Resources: are special variables that hold references to resources
external to PHP (such as database connections).
PHP ─ OPERATOR TYPES:
What is Operator:
Simple answer can be given using expression 4 + 5 is
equal to 9. Here 4 and 5 are called operands and + is called operator.
PHP language supports following type of operators.
Arithmetic Operators
Comparison Operators
Logical (or Relational) Operators
Assignment Operators
Conditional (or ternary) Operators
Let’s have a look on all operators one by one
Arithmetic Operators
Operator Description Example
+ Adds two operands A + B will give 30
- Subtracts second operand from the first A - B will give -10
* Multiply both operands A * B will give 200
/ Divide the numerator by denominator B / A will give 2
% Modulus Operator and remainder of after an integer division B % A will give 0
++ Increment operator, increases integer value by one A++ will give 11
-- Decrement operator, decreases integer value by one A-- will give 9
There are two types of control structures in PHP:
A. Conditional Statements
B. Control loops
Conditional Statements and loops having only one nested
statement do not require brackets, however programmers
frequently use them to make code more understandable. Nested
statements are often indented for the same reason.
 In simple terms, a control the flow of code execution in your
application. Generally, a program is executed sequentially, line
by line, and a, control structure allows you to alter that flow,
usually depending on certain conditions.
 Control structures are core features of the PHP language that
allow your script to respond differently to different inputs or
situations. This could allow your script to give different
responses based on user input, file contents, or some other
data.
if structure
 The if Statement
 Conditional structures are used to control which
statements get executed. They are composed of
three fundamental elements:
 if statements;
 elseif statements; and else statements.
Conditionals in PHP are structured similarly to those found in C++ and
Java. The structure begins with an if clause, which is composed of the
word "if" followed by a true/false statement in parentheses ( ).
The subsequent code will be contained in a block, denoted by curly
braces { }. Sometimes the braces are omitted, and only one line will
follow the if statement. elseif and else clauses sometimes occur after
the if clause, to test for different statements.
The if clause says "If this statement is true, I want the program to
execute the following statements. If it is false, then ignore these
statements." In technical terms, it works like this: When an if
statement is encountered, the true/false statement in parentheses is
evaluated.
 If the statement is found to be true, the subsequent block of code
contained in curly braces is executed. However, if the statement is
found to be false, the program skips those lines and executes the next
non-blank line.
 Our advanced PHP concepts provides you advance PHP topics,
tools, and advice that is technical to utilize them to develop
secure, performant, scalable, and reliable web applications.
During the advance PHP programming, find the power of PHP
as you take your site development skills to advance level.
 Cookies are small pieces of data stored as text on the client's
computer. Normally cookies are used only to store small
amounts of data. Even though cookies are not harmful some
people do not permit cookies due to concerns about their
privacy. In this case you have to use Sessions.
 Setting a cookie is extremely easy with setcookie().
 setcookie("test", "PHP-Hypertext-Preprocessor", time()+60,
"/location",1);
 Here the setcookie function is being called with four arguments
(setcookie has 1 more optional argument, not used here). In the above
code, the first argument is the cookie name, the second argument is
the cookie contents and the third argument is the time after which the
cookie should expire in seconds (time() returns current time in
seconds, there time()+60 is one minute from now). The path, or
location, element may be omitted, but it does allow you to easily set
cookies for all pages within a directory, although using this is not
generally recommended.
 If a server has set a cookie the browser sends it to the server each time
a page loads. The name of each cookie sent by your server is stored in
the super global array _COOKIE. So in the above example the cookie
would be retrieved by calling $_COOKIE['test']. To access data in the
cookie we use explode(). explode() turns a string into an array with a
certain delimiter present in the string. That is why we used those
dashes(- hyphens) in the cookie contents.
 So to retrieve and print out the full form of PHP from the cookie we
use the code:
 <? php
 $array = explode("-", $_COOKIE['test']); //retrieve contents of cookie
print("PHP stands for ".$array[0].$array[1].$array[2]); //display the
content
 ?>
 Note: $_COOKIE was Introduced in 4.1.0. In earlier versions, use.
 Cookies can be often used for: user preferences
inventories
 quiz or poll results shopping carts user authentication
 remembering data over a longer period
 You should never store unencrypted passwords in cookies as
cookies can be easily read by the users.
 You should never store critical data in cookies as cookies can be
easily removed or modified by users.
 Sessions allow the PHP script to store data on the web server that can
be later used, even between requests to different php pages.
 Every session has got a different identifier, which is sent to the client's
browser as a cookie or as a $_GET variable.
 Sessions end when the user closes the browser, or when the web
server deletes the session information, or when the programmer
explicitly destroys the session.
 In PHP it's usually called PHPSESSID. Sessions are very useful to
protect the data that the user wouldn't be able to read or write,
especially when the PHP developer doesn't want to give out
information in the cookies as they are easily readable.
 Sessions can be controlled by the $_SESSION super global. Data
stored in this array is persistent throughout the session. It is a simple
array.
 At the top of each php script that will be part of the current session
there must be the function session _ start(). It must be before the first
output ( echo or others ) or it will result in an error "Headers already
sent out".
 Session _ start();
 This function will do these actions:
 It will check the _COOKIE or _GET data, if it is given
 If the session file doesn't exist in the session . Save _ path location, it
will : Generate a new Unique Identifier, and
 Create a new file based on that Identifier, and Send a cookie to the
client's browser
 If it does exist, the PHP script will attempt to store the file's data into
_SESSION variable for further use
 Simple data such as integers, strings, and arrays can easily be stored
in the $_SESSION super global array and be passed from page to
page. Object state can be stored in a session by using the serialize()
function. serialize() will write the objects data into an array which
then can be stored in a $_SESSION super globlal.
 Unserialize () can be used to restore the state of an object before
trying to access the object in a page that is part of the current session.
 Avoiding Session Fixation Wikipedia has related information at
Session fixation
 Session fixation describes an attack vector in which a malicious
third-party sets (i.e. fixes) the session identifier (SID) of a user, and
is thus able to access that user's session.
THAN YOU….

More Related Content

What's hot

PHP
PHPPHP
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
JIGAR MAKHIJA
 
Software Design
Software DesignSoftware Design
Software Design
Spy Seat
 
Php tutorial
Php tutorialPhp tutorial
Php tutorialNiit
 
MySQL Presentation
MySQL PresentationMySQL Presentation
MySQL Presentation
Manish Bothra
 
Php advance
Php advancePhp advance
Php advance
Rattanjeet Singh
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
Yuriy Krapivko
 
Php notes
Php notesPhp notes
Php notes
Muthuganesh S
 
Php intro
Php introPhp intro
Php intro
sana mateen
 
Top 100 PHP Questions and Answers
Top 100 PHP Questions and AnswersTop 100 PHP Questions and Answers
Top 100 PHP Questions and Answers
iimjobs and hirist
 

What's hot (15)

Php ppt
Php pptPhp ppt
Php ppt
 
Php
PhpPhp
Php
 
PHP
PHPPHP
PHP
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Software Design
Software DesignSoftware Design
Software Design
 
Php Ppt
Php PptPhp Ppt
Php Ppt
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
MySQL Presentation
MySQL PresentationMySQL Presentation
MySQL Presentation
 
Php advance
Php advancePhp advance
Php advance
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
Php notes
Php notesPhp notes
Php notes
 
Php intro
Php introPhp intro
Php intro
 
Php introduction
Php introductionPhp introduction
Php introduction
 
Top 100 PHP Questions and Answers
Top 100 PHP Questions and AnswersTop 100 PHP Questions and Answers
Top 100 PHP Questions and Answers
 
phptutorial
phptutorialphptutorial
phptutorial
 

Similar to Unit 1

Php Interview Questions
Php Interview QuestionsPhp Interview Questions
Php Interview Questions
UmeshSingh159
 
Php&amp;yii2
Php&amp;yii2Php&amp;yii2
Php&amp;yii2
RakhiBhojwani
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Roohul Amin
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPtutorialsruby
 
Php
PhpPhp
chapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfchapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdf
burasyacob012
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
sushil kumar
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
Nguyễn Hoà
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
vigneswaran54
 
chapter Two Server-side Script lang.pptx
chapter  Two Server-side Script lang.pptxchapter  Two Server-side Script lang.pptx
chapter Two Server-side Script lang.pptx
alehegn9
 
Php
PhpPhp
Guidelines php 8 gig
Guidelines php 8 gigGuidelines php 8 gig
Guidelines php 8 gig
Ditinus Technology Pvt LTD
 
Php interview-questions and answers
Php interview-questions and answersPhp interview-questions and answers
Php interview-questions and answers
sheibansari
 
PHP Basics Ebook
PHP Basics EbookPHP Basics Ebook
PHP Basics EbookSwanand Pol
 
GTU MCA PHP Interview Questions And Answers for freshers
GTU MCA PHP  Interview Questions And Answers for freshersGTU MCA PHP  Interview Questions And Answers for freshers
GTU MCA PHP Interview Questions And Answers for freshers
TOPS Technologies
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)Arjun Shanka
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
rasool noorpour
 

Similar to Unit 1 (20)

Php Interview Questions
Php Interview QuestionsPhp Interview Questions
Php Interview Questions
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Php&amp;yii2
Php&amp;yii2Php&amp;yii2
Php&amp;yii2
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Php
PhpPhp
Php
 
chapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdfchapter 5 Server-Side Scripting (PHP).pdf
chapter 5 Server-Side Scripting (PHP).pdf
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
chapter Two Server-side Script lang.pptx
chapter  Two Server-side Script lang.pptxchapter  Two Server-side Script lang.pptx
chapter Two Server-side Script lang.pptx
 
Php
PhpPhp
Php
 
Guidelines php 8 gig
Guidelines php 8 gigGuidelines php 8 gig
Guidelines php 8 gig
 
Php interview-questions and answers
Php interview-questions and answersPhp interview-questions and answers
Php interview-questions and answers
 
phptutorial
phptutorialphptutorial
phptutorial
 
PHP Basics Ebook
PHP Basics EbookPHP Basics Ebook
PHP Basics Ebook
 
GTU MCA PHP Interview Questions And Answers for freshers
GTU MCA PHP  Interview Questions And Answers for freshersGTU MCA PHP  Interview Questions And Answers for freshers
GTU MCA PHP Interview Questions And Answers for freshers
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 

Unit 1

  • 1. NAME OF STAFF :S.SAYI PRIYA NAME OF STUDENT : J.THEORITA REGISTER NUMBER :CB17S 250447 CLASS :III-BCA-B BATCH :2017-2020 YEAR :2020 SUBJECT CODE :MCA511
  • 2. INTRODUCTION IN PHP PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994. PHP is a recursive acronym for "PHP: Hypertext Preprocessor". PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.
  • 3. It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server. PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the Unix side. The MySQL server, once started, executes even very complex queries with huge result sets in record-setting time PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added support for Java and distributed object architectures (COM and CORBA), making n-tier development a possibility for the first time
  • 4. PHP is forgiving: PHP language tries to be as forgiving as possible. PHP Syntax is C-Like Characteristics of PHP: o Five important characteristics make PHP's practical nature possible:  Simplicity Efficiency Security Flexibility Familiarity
  • 5. PHP ─ VARIABLE TYPES  The main way to store information in the middle of a PHP program is by using a variable. Here are the most important things to know about variables in PHP.  All variables in PHP are denoted with a leading dollar sign ($).  The value of a variable is the value of its most recent assignment.  Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.  Variables can, but do not need, to be declared before assignment.  Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters.
  • 6. PHP has a total of eight data types which we use to construct our variables: o Integers: are whole numbers, without a decimal point, like 4195. o Doubles: are floating-point numbers, like 3.14159 or 49.1. o Booleans: have only two possible values either true or false. o NULL: is a special type that only has one value: NULL. o Strings: are sequences of characters, like 'PHP supports string operations.' o Arrays: are named and indexed collections of other values. o Objects: are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class. o Resources: are special variables that hold references to resources external to PHP (such as database connections).
  • 7. PHP ─ OPERATOR TYPES: What is Operator: Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. PHP language supports following type of operators. Arithmetic Operators Comparison Operators Logical (or Relational) Operators Assignment Operators Conditional (or ternary) Operators Let’s have a look on all operators one by one
  • 8. Arithmetic Operators Operator Description Example + Adds two operands A + B will give 30 - Subtracts second operand from the first A - B will give -10 * Multiply both operands A * B will give 200 / Divide the numerator by denominator B / A will give 2 % Modulus Operator and remainder of after an integer division B % A will give 0 ++ Increment operator, increases integer value by one A++ will give 11 -- Decrement operator, decreases integer value by one A-- will give 9
  • 9. There are two types of control structures in PHP: A. Conditional Statements B. Control loops Conditional Statements and loops having only one nested statement do not require brackets, however programmers frequently use them to make code more understandable. Nested statements are often indented for the same reason.
  • 10.  In simple terms, a control the flow of code execution in your application. Generally, a program is executed sequentially, line by line, and a, control structure allows you to alter that flow, usually depending on certain conditions.  Control structures are core features of the PHP language that allow your script to respond differently to different inputs or situations. This could allow your script to give different responses based on user input, file contents, or some other data.
  • 11. if structure  The if Statement  Conditional structures are used to control which statements get executed. They are composed of three fundamental elements:  if statements;  elseif statements; and else statements.
  • 12. Conditionals in PHP are structured similarly to those found in C++ and Java. The structure begins with an if clause, which is composed of the word "if" followed by a true/false statement in parentheses ( ). The subsequent code will be contained in a block, denoted by curly braces { }. Sometimes the braces are omitted, and only one line will follow the if statement. elseif and else clauses sometimes occur after the if clause, to test for different statements. The if clause says "If this statement is true, I want the program to execute the following statements. If it is false, then ignore these statements." In technical terms, it works like this: When an if statement is encountered, the true/false statement in parentheses is evaluated.  If the statement is found to be true, the subsequent block of code contained in curly braces is executed. However, if the statement is found to be false, the program skips those lines and executes the next non-blank line.
  • 13.  Our advanced PHP concepts provides you advance PHP topics, tools, and advice that is technical to utilize them to develop secure, performant, scalable, and reliable web applications. During the advance PHP programming, find the power of PHP as you take your site development skills to advance level.
  • 14.  Cookies are small pieces of data stored as text on the client's computer. Normally cookies are used only to store small amounts of data. Even though cookies are not harmful some people do not permit cookies due to concerns about their privacy. In this case you have to use Sessions.
  • 15.  Setting a cookie is extremely easy with setcookie().  setcookie("test", "PHP-Hypertext-Preprocessor", time()+60, "/location",1);  Here the setcookie function is being called with four arguments (setcookie has 1 more optional argument, not used here). In the above code, the first argument is the cookie name, the second argument is the cookie contents and the third argument is the time after which the cookie should expire in seconds (time() returns current time in seconds, there time()+60 is one minute from now). The path, or location, element may be omitted, but it does allow you to easily set cookies for all pages within a directory, although using this is not generally recommended.
  • 16.  If a server has set a cookie the browser sends it to the server each time a page loads. The name of each cookie sent by your server is stored in the super global array _COOKIE. So in the above example the cookie would be retrieved by calling $_COOKIE['test']. To access data in the cookie we use explode(). explode() turns a string into an array with a certain delimiter present in the string. That is why we used those dashes(- hyphens) in the cookie contents.  So to retrieve and print out the full form of PHP from the cookie we use the code:  <? php  $array = explode("-", $_COOKIE['test']); //retrieve contents of cookie print("PHP stands for ".$array[0].$array[1].$array[2]); //display the content  ?>  Note: $_COOKIE was Introduced in 4.1.0. In earlier versions, use.
  • 17.  Cookies can be often used for: user preferences inventories  quiz or poll results shopping carts user authentication  remembering data over a longer period  You should never store unencrypted passwords in cookies as cookies can be easily read by the users.  You should never store critical data in cookies as cookies can be easily removed or modified by users.
  • 18.  Sessions allow the PHP script to store data on the web server that can be later used, even between requests to different php pages.  Every session has got a different identifier, which is sent to the client's browser as a cookie or as a $_GET variable.  Sessions end when the user closes the browser, or when the web server deletes the session information, or when the programmer explicitly destroys the session.  In PHP it's usually called PHPSESSID. Sessions are very useful to protect the data that the user wouldn't be able to read or write, especially when the PHP developer doesn't want to give out information in the cookies as they are easily readable.  Sessions can be controlled by the $_SESSION super global. Data stored in this array is persistent throughout the session. It is a simple array.
  • 19.  At the top of each php script that will be part of the current session there must be the function session _ start(). It must be before the first output ( echo or others ) or it will result in an error "Headers already sent out".  Session _ start();  This function will do these actions:  It will check the _COOKIE or _GET data, if it is given  If the session file doesn't exist in the session . Save _ path location, it will : Generate a new Unique Identifier, and  Create a new file based on that Identifier, and Send a cookie to the client's browser  If it does exist, the PHP script will attempt to store the file's data into _SESSION variable for further use
  • 20.  Simple data such as integers, strings, and arrays can easily be stored in the $_SESSION super global array and be passed from page to page. Object state can be stored in a session by using the serialize() function. serialize() will write the objects data into an array which then can be stored in a $_SESSION super globlal.  Unserialize () can be used to restore the state of an object before trying to access the object in a page that is part of the current session.  Avoiding Session Fixation Wikipedia has related information at Session fixation  Session fixation describes an attack vector in which a malicious third-party sets (i.e. fixes) the session identifier (SID) of a user, and is thus able to access that user's session.