Advanced-Web-System
Advanced-Web-System
Advanced
Web System
E m m a n u e l T. F l o r e s , M I T
1
Click to edit Master title style
Introduction
Intro to Web Development: PHP
2 2
Click
PHP to edit Master title style
3 3
Click
PHP to edit Master title style
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 MUST for students and working professionals to become a great Software Engineer specially
when they are working in Web Development Domain. I will list down some of the key advantages of
learning PHP:
• 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.
4 4
• PHP is forgiving: PHP language tries to be as forgiving as possible.
Click
Commonto edit
usesMaster
of PHP title style
As mentioned before, PHP is one of the most widely used
language over the web. I'm going to list few of them here:
• PHP performs system functions, i.e. from files on a system it can create,
open, read, write, and close them.
• PHP can handle forms, i.e. gather data from files, save data to a file,
through email you can send data, return data to the user.
• You add, delete, modify elements within your database through PHP.
• Access cookies variables and set cookies.
• Using PHP, you can restrict users to access some pages of your
website.
• It can encrypt data.
5 5
Click to edit Master title style
Hello World
7 7
Click
PHP -to edit Master
Syntax title- style
Overview Escaping to PHP
ASP-style tags
ASP-style tags mimic the tags used by Active Server Pages to
delineate code blocks. ASP-style tags look like this −
8 8
Click
PHP -to edit Master
Syntax title style
Overview
9 9
Click
PHP -to edit Master
Syntax title style
Overview
10
10
Click
PHP -to edit Master
Syntax title style
Overview
11
11
Click
PHP -to edit Master
Syntax title style
Overview
12
12
Click
PHP -to edit Master
Syntax title style
Overview
13
13
Click
PHP -to edit Master
Variable Typestitle style
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.
• Variables used before they are assigned have default values.
• PHP does a good job of automatically converting types from one to another when necessary.
• PHP variables are Perl-like.
14
14
Click
PHP -to edit Master
Variable Typestitle style
PHP has a total of eight data types which we use to construct our variables:
• Integers − are whole numbers, without a decimal point, like 4195.
• Doubles − are floating-point numbers, like 3.14159 or 49.1.
• Booleans − have only two possible values either true or false.
• NULL − is a special type that only has one value: NULL.
• Strings − are sequences of characters, like 'PHP supports string operations.'
• Arrays − are named and indexed collections of other values.
• Objects − are instances of programmer-defined classes, which can package up both other
kinds of values and functions that are specific to the class.
• Resources − are special variables that hold references to resources external to PHP (such as
database connections).
15
15
Click
PHP -to edit Master
Variable Typestitle style
- Integers
They are whole numbers, without a decimal point, like 4195. They are the simplest type .they
correspond to simple whole numbers, both positive and negative. Integers can be assigned to
variables, or they can be used in expressions.
16
16
Click
PHP -to edit Master
Variable Typestitle style
- Doubles
They like 3.14159 or 49.1. By default, doubles print with the minimum number of decimal places
needed. For example, the code −
17
17
Click
PHP -to edit Master
Variable Typestitle style
- Boolean
They have only two possible values either true or false. PHP provides a couple of constants
especially for use as Booleans: TRUE and FALSE, which can be used like so -
18
18
Click
PHP -to edit Master
Variable Typestitle style
- Boolean
19
19
Click to edit Master title style
PHP - Boolean
Each of the following variables has the truth value embedded in its name when it is used in a
Boolean context.
20
20
Click to edit Master title style
PHP - NULL
NULL is a special type that only has one value: NULL. To give a variable the NULL value, simply
assign it like this −
The special constant NULL is capitalized by convention, but actually it is case insensitive; you
could just as well have typed −
A variable that has been assigned NULL has the following properties −
• It evaluates to FALSE in a Boolean context.
• It returns FALSE when tested with IsSet() function.
21
21
Click to edit Master title style
PHP - Strings
22
22
Click
PHP -to edit Master title style
Strings
There are no artificial limits on string length - within the bounds of available memory, you ought
to be able to make arbitrarily long strings.
Strings that are delimited by double quotes (as in "this") are preprocessed in both the following
two ways by PHP:
• Certain character sequences beginning with backslash (\) are replaced with special characters
• Variable names (starting with $) are replaced with string representations of their values.
Output:
The length of a string is often used in loops or other functions, when it is important to know
when the string ends. (i.e. in a loop, we would want to stop the loop after the last character
in the string)
25
25
Click
PHP –to edit Master
String title
Using the stylefunction
strpos()
The strpos() function is used to search for a string or character
within a string.
If a match is found in the string, this function will return the
position of the first match. If no match is found, it will return
FALSE.
Let's see if we can find the string "world" in our string −
Output:
26
26
Click to edit
PHP - GET Master
& POST title style
Methods
There are two ways the browser client can send information to
the web server.
• The GET Method
• The POST Method
Before the browser sends the information, it encodes it using a scheme called
URL encoding. In this scheme, name/value pairs are joined with equal signs and
different pairs are separated by the ampersand.
Spaces are removed and replaced with the + character and any other nonalphanumeric
characters are replaced with a hexadecimal values. After the information is encoded it is
sent to the server.
27
27
Click to edit
PHP - The GETMaster
Method title style
The GET method sends the encoded user information
appended to the page request. The page and the encoded
information are separated by the ? character.
• The GET method produces a long string that appears in your server logs, in the browser's
Location: box.
• The GET method is restricted to send upto 1024 characters only.
• Never use GET method if you have password or other sensitive information to be sent to the
server.
• GET can't be used to send binary data, like images or word documents, to the server.
• The data sent by GET method can be accessed using QUERY_STRING environment variable.
• The PHP provides $_GET associative array to access all the sent information using GET method.
28
28
Click to edit
PHP - The GETMaster
Method title style
The GET method sends the encoded user information
appended to the page request. The page and the encoded
information are separated by the ? character.
• The GET method produces a long string that appears in your server logs, in the browser's
Location: box.
• The GET method is restricted to send upto 1024 characters only.
• Never use GET method if you have password or other sensitive information to be sent to the
server.
• GET can't be used to send binary data, like images or word documents, to the server.
• The data sent by GET method can be accessed using QUERY_STRING environment variable.
• The PHP provides $_GET associative array to access all the sent information using GET method.
29
29
Click to edit
PHP - The GETMaster
Method title style
The GET method sends the encoded user information
appended to the page request. The page and the encoded
information are separated by the ? character.
• The GET method produces a long string that appears in your server logs, in the browser's
Location: box.
• The GET method is restricted to send upto 1024 characters only.
• Never use GET method if you have password or other sensitive information to be sent to the
server.
• GET can't be used to send binary data, like images or word documents, to the server.
• The data sent by GET method can be accessed using QUERY_STRING environment variable.
• The PHP provides $_GET associative array to access all the sent information using GET method.
30
30
Click to edit
PHP - The POSTMaster
Methodtitle style
The POST method transfers information via HTTP headers. The
information is encoded as described in case of GET method and
put into a header called QUERY_STRING.
• The POST method does not have any restriction on data size to be sent.
• The POST method can be used to send ASCII as well as binary data.
• The data sent by POST method goes through HTTP header so security depends on HTTP
protocol. By using Secure HTTP you can make sure that your information is secure.
• The PHP provides $_POST associative array to access all the sent information using POST
method.
31
31
Click to edit Master title style
PHP - Functions
PHP functions are similar to other programming languages. A
function is a piece of code which takes one more input in the
form of parameter and does some processing and returns a
value.
32
32
Click to edit Master
PHP Creating title style
PHP Function
PHP functions are similar to other programming
languages. A function is a piece of code which takes
one more input in the form of parameter and does
some processing and returns a value.
33
33
Click to edit Master title style
PHP Functions with Parameters
PHP gives you option to pass your parameters inside a function. You can pass as many as parameters your
like.
These parameters work like variables inside your function. Following example takes two integer parameters
and add them together and then print them.
34
34