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

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 PHPstarted 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 integratedwith 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 ─ VARIABLETYPES  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 atotal 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 ─ OPERATORTYPES: 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 DescriptionExample + 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 twotypes 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 simpleterms, 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  Theif 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 PHPare 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 advancedPHP 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 aresmall 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 acookie 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 aserver 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 canbe 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 allowthe 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 thetop 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 datasuch 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.
  • 21.