You are on page 1of 60

Introduction to web

techniques
Concept of WWW.
• WWW is stands for World Wide Web.
• The World Wide Web (WWW) is a global information medium which users can read and write via computer
connected to the internet.
• The Web, or World Wide Web, is basically a system of Internet servers that support specially formatted
documents. The documents are formatted in a markup language called HTML
• (Hypertext Markup Language) that supports links to other documents, as well as graphics, audio, and video files.
• In short, World Wide Web (WWW) is collection of text pages, digital photographs, music files, videos, and
animations you can access over the Internet.
• Web pages are primarily text documents formatted and annotated with Hypertext Markup Language (HTML). In
addition to formatted text, web pages may contain images, video, and software components that are rendered
in the user's web browser as coherent pages of multimedia content.
• The terms Internet and World Wide Web are often used without much distinction. However, the two are not
the same.
• The Internet is a global system of interconnected computer networks. In
contrast, the World Wide Web is one of the services transferred over these
networks. It is a collection of text documents and other resources, linked by
hyperlinks and URLs, usually accessed by web browsers, from web servers.
• There are several applications called Web browsers that make it easy to
access the World Wide Web; For example: Firefox ,Microsoft's Internet
Explorer, Chrome Etc.
• Users access the World-Wide Web facilities via a client called a browser,
which provides transparent access to the WWW servers.
• What is The Internet?
• The Internet is a massive network of networks, a networking infrastructure. It connects
millions of computers together globally, forming a network in which any computer can
communicate with any other computer as long as they are both connected to the Internet.
• Information that travels over the Internet does so via a variety of languages known as
protocols. So we can says that Internet is network of computer which connect to together and
any computer communicate with any other computer.
• What is The Web (World Wide Web)?
• The World Wide Web, or simply Web, is a way of accessing information over the medium of
the Internet. It is an information-sharing model that is built on top of the Internet.
• The Web uses the HTTP protocol, only one of the languages spoken over the Internet, to
transmit data. The Web also utilizes browsers, such as Internet Explorer or Firefox, to access
Web documents called Web pages that are linked to each other via hyperlinks. Web
documents also contain graphics, sounds, text and video.
• Different between Internet and WWW
• The Web is a Portion of The Internet. The Web is just one of the ways that information can be
disseminated over the Internet. The Internet, not the Web, is also used for email, which relies
on SMTP, Usenet news groups, instant messaging and FTP. So the Web is just a portion of the
Internet.
• HTTP Protocol: Request and Response.
• HTTP stands for Hypertext Transfer Protocol.
• HTTP is based on the client-server architecture model and a stateless request/response protocol
that operates by exchanging messages across a reliable TCP/IP connection.
• An HTTP "client" is a program (Web browser) that establishes a connection to a server for the
purpose of sending one or more HTTP request messages. An HTTP "server" is a program
(generally a web server like Apache Web Server) that accepts connections in order to serve
HTTP requests by sending HTTP response messages.
• Errors on the Internet can be quite frustrating — especially if you do not know the difference
between a 404 error and a 502 error. These error messages, also called HTTP status codes a
response codes given by Web servers and help identify the cause of the problem.
• For example, "404 File Not Found" is a common HTTP status code. It means the Web server
cannot find the file you requested. The file -- the webpage or other document you try to load in
your Web browser has either been moved or deleted, or you entered the wrong URL or
document name.
• HTTP is a stateless protocol means the HTTP Server doesn't maintain the contextual
information about the clients communicating with it and hence we need to maintain
sessions in case we need that feature for our Web-applications
• HTTP header fields provide required information about the request or response, or
about the object sent in the message body. There are four types of HTTP message
headers:
• General-header:
• These header fields have general applicability for both request and response
messages.
• Request-header:
• These header fields have applicability only for request messages.
• Response-header:
• These header fields have applicability only for response messages.
• Entity-header:
• These header fields define Meta information about the entity-body.
• As mentioned, whenever you enter a URL in the address box of the browser, the
browser translates the URL into a request message according to the specified protocol;
and sends the request message to the server.
• Web Browser and Web Server.
• Web server and web browser are the terms which are commonly used for website.
The basic purpose of both is to develop a platform for internet web directory. So that
any users can anytime access any kind of website. Major difference between them is
on their function and how they perform their functions. Check for the detail of both
topics before understanding the differences between them.
• Web Browser
• Web browser is a client, program, software or tool through which we sent HTTP
request to web server. The main purpose of web browser is to locate the content on
the World Wide Web and display in the shape of web page, image, audio or video
form.
• We can also call it a client server because it contacts the web server for desired
information. If the requested data is available in the web server data then it will send
back the requested information again via web browser. Microsoft Internet Explorer,
Mozilla Firefox, Safari, Opera and Google Chrome are examples of
• web browser and they are more advanced than earlier web browser because they are
capable to understand the HTML, JavaScript, AJAX, etc. Now days, web browser for
mobiles are also available, which are called micro browser.
• Web Server
• Web server is a computer system, which provides the web pages via HTTP
(Hypertext Transfer Protocol). IP address and a domain name is essential
for every web server.
• Whenever, you insert a URL or web address into your web browser, this
sends request to the web address where domain name of your URL is
already saved. Then this server collects the all information of your web
page and sends to browser, which you see in form of web page on your
browser.
• Lot of web server software is available in the market in shape of NCSA
National Center for Supercomputing Applications , Apache, Microsoft
and Netscape. Storing, processing and delivering web pages to clients are
its main function. All the communication between client (web browser)
and server takes place via HTTP.
• What are Scripting languages?
• A script or scripting language is a computer language that does not need the
compilation step and is rather interpreted one by one at runtime. It is where
the script is written and where instructions for a run-time environment are
written. In contrast to programming languages that are compiled first before
running, scripting languages do not compile the file and execute the file
without being compiled.
• Scripts are often utilized to create dynamic web applications now a days
because they are linked to web development. Server-Side Scripting Languages
and Client-Side Scripting Languages are the two types of scripting languages.
Python, PHP, and Perl are examples of server-side scripting languages, while
JavaScript is the greatest example of a client-side scripting language. These
languages are often developed with the goal of communicating with other
programming languages.
Scripting Language Programming Language

A scripting language is a language that uses A Programming language is a language which is


1. a native method to bring codes to a runtime used by humans to navigate their
environment communication with computers.

Programming languages are of three types -:


These are made for a particular runtime low-level Programming language
2.
environment. Middle-level Programming language
High-level Programming language

They are used to create dynamic web Programming languages are used to write
3.
applications computer programs.
4. Example -: Bash, Ruby, Python,PHP Example -: C++, Java, High-level

Scripting languages can be easily ported among Programming languages are


5.
various operating systems. translation free languages

6. These languages requires a host. These languages are self executable.

7. Do not create a .exe file. These generate .exe files.

Most of the scripting languages are interpreted Most of the programming languages
8.
language. are compiled languages.

All the scripting languages are programming All the programming languages are
9.
languages. not scripting languages.
• What does PHP stand for ?
• PHP is a server scripting language, and a powerful tool for making dynamic and
interactive Web pages.
• PHP is a widely-used, free, and efficient alternative to competitors such as
Microsoft's ASP.
• PHP code is executed on the server.
• PHP is an acronym for "PHP: Hypertext Preprocessor"
• PHP is a widely-used, open source scripting language
• PHP scripts are executed on the server
• PHP is free to download and use
• What is a PHP File?
• PHP files can contain text, HTML, CSS, JavaScript, and PHP code
• PHP code is executed on the server, and the result is returned to the browser as
plain HTML
• PHP files have extension ".php"
• What Can PHP Do?
• PHP can generate dynamic page content
• PHP can create, open, read, write, delete, and close files on the server
• PHP can collect form data
• PHP can send and receive cookies
• PHP can add, delete, modify data in your database
• PHP can be used to control user-access
• PHP can encrypt data
• With PHP you are not limited to output HTML. You can output images, PDF files, and
even Flash movies. You can also output any text, such as XHTML and XML.
• Why PHP?
• PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
• PHP is compatible with almost all servers used today (Apache, IIS, etc.)
• PHP supports a wide range of databases
• PHP is free. Download it from the official PHP resource: www.php.net
• PHP is easy to learn and runs efficiently on the server side
• HTTP stands for Hyper Text Transfer Protocol
• WWW is about communication between web clients and servers
• Communication between client computers and web servers is done by
sending HTTP Requests and receiving HTTP Response
• World Wide Web Communication
• The World Wide Web is about communication between web clients and web
servers.
• Clients are often browsers (Chrome, Edge, Safari), but they can be any type of
program or device.
• Servers are most often computers in the cloud.
• HTTP Request / Response
• Communication between clients and servers is done by requests and responses:
• A client (a browser) sends an HTTP request to the web
• A web server receives the request
• The server runs an application to process the request
• The server returns an HTTP response (output) to the browser
• The client (the browser) receives the response
• The HTTP Request Circle
• A typical HTTP request / response circle:
• The browser requests an HTML page. The server returns an HTML file.
• The browser requests a style sheet. The server returns a CSS file.
• The browser requests an JPG image. The server returns a JPG file.
• The browser requests JavaScript code. The server returns a JS file
• The browser requests data. The server returns data (in XML or JSON).
• XHR - XML Http Request
• All browsers have a built-in XMLHttpRequest Object (XHR).
• XHR is a JavaScript object that is used to transfer data between a web browser and a
web server.
• XHR is often used to request and receive data for the purpose of modifying a web
page.
• Despite the XML and Http in the name, XHR is used with other protocols than HTTP,
and the data can be of many different types like HTML, CSS, XML, JSON, and plain
text.
• The XHR Object is a Web Developers Dream, because you can:
• Update a web page without reloading the page
• Request data from a server - after the page has loaded
• Receive data from a server - after the page has loaded
• Send data to a server - in the background
• The XHR Object is the underlying concept of AJAX and JSON:
4
The scripting engine <? $variables_data ?>
3 <?php ?> process the request
<% asp %>
<html> custom data
</html>
and sends it on to the
scripting language

2 Server takes ..and sent back to


information you out you as a web page
in
5

1 Your Data!
You visit the site
Give input
• Set Up PHP on Your Own PC
• However, if your server does not support PHP, you must:
• install a web server
• install PHP
• install a database, such as MySQL
• The official PHP website (PHP.net) has installation instructions for PHP:
http://php.net/manual/en/install.php
• Some example of php website :
• WordPress • Yahoo
• Facebook • Drupal
• Etsy • Spotify
• Wikipedia • Magento
• Slack • Pfizer
• Tumblr • Peloton
• MailChimp • Moodle
• Canva
• Lexical Structure
• The lexical structure of a programming language is the set of basic rules that governs how you write
programs in that language
• Basic PHP Syntax
• A PHP script can be placed anywhere in the document.
• A PHP script starts with <?php and ends with ?>:
<?php
// PHP code goes here
?>
• The default file extension for PHP files is ".php".
• A PHP file normally contains HTML tags, and some PHP scripting code.
• Below, we have an example of a simple PHP file, with a PHP script that uses a
built-in PHP function "echo" to output the text "Hello World!" on a web page:

<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
PHP Case Sensitivity

In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined
functions are not case-sensitive.
In the example below, all three echo statements below are equal and legal:
<!DOCTYPE html>
<html>
<body>

<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>

</body>
</html>
• Look at the example below; only the first statement will display the value
of the $color variable! This is because $color, $COLOR, and $coLOR are
treated as three different variables:
<!DOCTYPE html>
<html>
<body>

<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?>

</body>
</html
• Comments in PHP
<!DOCTYPE html>
• A comment in PHP code is a line that is not <html>
<body>
executed as a part of the program. Its only
purpose is to be read by someone who is <?php
looking at the code. // This is a single-line comment

• Comments can be used to: # This is also a single-line comment

• Remind yourself of what you did - Most /*


This is a multiple-lines comment
programmers have experienced coming back block
to their own work a year or two later and that spans over multiple
having to re-figure out what they did. lines
*/
Comments can remind you of what you were ?>
thinking when you wrote the code
</body>
• PHP supports several ways of commenting: </html>
Try it Yourself »
• Creating (Declaring) PHP Variables
• In PHP, a variable starts with the $ sign, followed by the name of the variable:
<!DOCTYPE html>
<html>
<body> Output:
<?php Hey
Hello world!
$txt = "Hello world!"; 5
$x = 5; 10.5
$y = 10.5;
echo $txt;
echo "<br>";
echo $x;
echo "<br>";
echo $y;
?>
</body>
</html>
• PHP Variables
• A variable can have a short name (like x and y) or a more descriptive name
(age, carname, total_volume).
• Rules for PHP variables:
• A variable starts with the $ sign, followed by the name of the variable
• A variable name must start with a letter or the underscore character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and underscores
(A-z, 0-9, and _ )
• Variable names are case-sensitive ($age and $AGE are two different variables)
• Remember that PHP variable names are case-sensitive!
• Output Variables
• The PHP echo statement is often used to output data to the screen.
• The following example will show how to output text and a variable:
<!DOCTYPE html>
<html>
<body>

<?php
$txt = “Sybca”
echo " Web Tech $txt!";

$txt = " Sybca ";


echo “Web Tech" . $txt . "!";

?>
</body>
</html>

Output:
Web Tech Sybca!
Web Tech Sybca!
• <!DOCTYPE html>
• <html>
• <body>
• <?php
• $x = 5;
• $y = 4;
• echo $x + $y;
• ?>
• </body>
• </html>
Output
•9
• PHP is a Loosely Typed Language
• In the example above, notice that we did not have to tell PHP which data type the
variable is.
• PHP automatically associates a data type to the variable, depending on its value.
Since the data types are not set in a strict sense, you can do things like adding a
string to an integer without causing an error.
• In PHP 7, type declarations were added. This gives an option to specify the data type
expected when declaring a function, and by enabling the strict requirement, it will
throw a "Fatal Error" on a type mismatch.
• PHP Variables Scope
• In PHP, variables can be declared anywhere in the script.
• The scope of a variable is the part of the script where the variable can be
referenced/used.
• PHP has three different variable scopes:
• local
• global
• static
• Global and Local Scope
• A variable declared outside a function has a GLOBAL SCOPE and can only be
accessed outside a function:
<!DOCTYPE html>
<html>
<body>
Variable x inside function is:
<?php Variable x outside function is: 5
$x = 5; // global scope
function myTest() {
// using x inside this function will generate an error
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
echo "<p>Variable x outside function is: $x</p>";
?>
</body>
</html>
<!DOCTYPE html>
<html>
<body>

<?php
function myTest() {
$x = 5; // local scope
echo "<p>Variable x inside function is: $x</p>";
}
myTest();

// using x outside the function will generate an error


echo "<p>Variable x outside function is: $x</p>";
?>

</body>
</html>
<!DOCTYPE html>
<html>
<body> Variable x inside function is: 5

<?php Variable x outside function is:


function myTest() {
$x = 5; // local scope
echo "<p>Variable x inside function is: $x</p>";
}
myTest();
// using x outside the function will generate an error
echo "<p>Variable x outside function is: $x</p>";
?>
</body>
</html>
You can have local variables with the same name in different functions, because local variables
are only recognized by the function in which they are declared.
• PHP The global Keyword
• The global keyword is used to access a global variable from within a function.
• To do this, use the global keyword before the variables (inside the function):
<!DOCTYPE html>
<html>
<body>
<?php
$x = 5; Output : 15
$y = 10;
function myTest() {
global $x, $y;
$y = $x + $y;
}
myTest(); // run function
echo $y; // output the new value for variable $y
?>
</body>
</html>
• PHP also stores all global variables in an array called $GLOBALS[index]. The index holds the name of
the variable. This array is also accessible from within functions and can be used to update global
variables directly.
• The example above can be rewritten like this:
<!DOCTYPE html> Output: 15
<html>
<body>
<?php
$x = 5;
$y = 10;
function myTest() {
$GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
}
myTest();
echo $y;
?>
</body>
</html>
• PHP The static Keyword <!DOCTYPE html>
• Normally, when a function is <html>
completed/executed, all of its variables are <body>
deleted. However, sometimes we want a local <?php
variable NOT to be deleted. We need it for a function myTest() {
further job. static $x = 0;
• To do this, use the static keyword when you first echo $x;
declare the variable: $x++;
• Output: }
0 myTest();
1 echo "<br>";
2 myTest();
• Then, each time the function is called, that echo "<br>";
variable will still have the information it myTest();
contained from the last time the function was ?>
called. </body>
• Note: The variable is still local to the function. </html>
• PHP echo and print Statements
• echo and print are more or less the same. They are both used to output data to the
screen.
• The differences are small: echo has no return value while print has a return value of
1 so it can be used in expressions. echo can take multiple parameters (although
such usage is rare) while print can take one argument. echo is marginally faster
than print.
• The PHP echo Statement
• The echo statement can be used with or without parentheses: echo or echo().
• Display Text
• The following example shows how to output text with the echo command (notice
that the text can contain HTML markup):
• <?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple
parameters.";
?>
• The PHP print Statement
• The print statement can be used with or without parentheses: print or
print().
• Display Text
• The following example shows how to output text with the print command
(notice that the text can contain HTML markup):
• <?php
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
• Display Variables
• The following example shows how to output text and variables with the
print statement:
• <?php
$txt1 = "Learn PHP";
$txt2 = “programming";
$x = 5;
$y = 4;

print "<h2>" . $txt1 . "</h2>";


print "Study PHP” . $txt2 . "<br>";
print $x + $y;
?>
• PHP Data Types
• Variables can store data of different types, and different data types can do different things.
• PHP supports the following data types:
• String
• Integer
• Float (floating point numbers - also called double)
• Boolean
• Array
• Object
• NULL
• Resource
• PHP String
• A string is a sequence of characters, like "Hello world!".
• A string can be any text inside quotes. You can use single or double quotes:
• <?php
$x = "Hello world!";
$y = 'Hello world!';
echo $x;
echo "<br>";
echo $y;
?>
• PHP Integer
• An integer data type is a non-decimal number between -2,147,483,648 and
2,147,483,647.
• Rules for integers:
• An integer must have at least one digit
• An integer must not have a decimal point
• An integer can be either positive or negative
• Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base
8), or binary (base 2) notation
• In the following example $x is an integer. The PHP var_dump() function returns
the data type and value:
• <?php
$x = 5985;
var_dump($x);
?>
• PHP Float
• A float (floating point number) is a number with a decimal point or a number in
exponential form.
• In the following example $x is a float. The PHP var_dump() function returns the
data type and value:
• <?php
$x = 10.365;
var_dump($x);
?>
• PHP Boolean
• A Boolean represents two possible states: TRUE or FALSE.
• $x = true;
• $y = false;
• Booleans are often used in conditional testing.
• PHP Array
• An array stores multiple values in one single variable.
• In the following example $cars is an array. The PHP var_dump()
function returns the data type and value:
• <?php
$cars = array("Volvo","BMW","Toyota");
var_dump($cars);
?>
• PHP Object
• Classes and objects are the two main aspects of object-oriented programming.
• A class is a template for objects, and an object is an instance of a class.
• When the individual objects are created, they inherit all the properties and
behaviors from the class, but each object will have different values for the
properties.
• Let's assume we have a class named Car. A Car can have properties like model,
color, etc. We can define variables like $model, $color, and so on, to hold the
values of these properties.
• When the individual objects (Volvo, BMW, Toyota, etc.) are created, they
inherit all the properties and behaviors from the class, but each object will
have different values for the properties.
• If you create a __construct() function, PHP will automatically call this function
when you create an object from a class.
• <?php
class Car {
public $color;
public $model;
public function __construct($color, $model) {
$this->color = $color;
$this->model = $model;
}
public function message() {
return "My car is a " . $this->color . " " . $this->model
. "!";
}
}
$myCar = new Car("black", "Volvo");
echo $myCar -> message();
echo "<br>";
$myCar = new Car("red", "Toyota");
echo $myCar -> message();
?>
• PHP NULL Value
• Null is a special data type which can have only one value: NULL.
• A variable of data type NULL is a variable that has no value assigned to it.
• Tip: If a variable is created without a value, it is automatically assigned a value of NULL.
• Variables can also be emptied by setting the value to NULL:
• <?php
$x = "Hello world!";
$x = null;
var_dump($x);
?>
• PHP Resource
• The special resource type is not an actual data type. It is the storing of a reference to
functions and resources external to PHP.

• A common example of using the resource data type is a database call.

• We will not talk about the resource type here, since it is an advanced topic.
PHP Conditional Statements
Very often when you write code, you want to perform different actions for
different conditions. You can use conditional statements in your code to do
this.
In PHP we have the following conditional statements:
•if statement - executes some code if one condition is true
•if...else statement - executes some code if a condition is true and another
code if that condition is false
•if...elseif...else statement - executes different codes for more than two
conditions
•switch statement - selects one of many blocks of code to be executed
•PHP - The if Statement
•The if statement executes some code if one condition is true.

•Syntax
•if (condition) {
• code to be executed if condition is true;
•}
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
}
?>
• Example
• Output "Have a good day!" if the current time (HOUR) is less than 20:
• PHP - The if...else Statement
• The if...else statement executes some code if a condition is true and another code if that
condition is false.
• Syntax
if (condition) {
code to be executed if condition is true;
} elseif(condition)
{
code to be executed if condition is false;
<!DOCTYPE html>
<html>
<body>
<?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?>
</body>
</html>
PHP Loops
Often when you write code, you want the same block of code to run over and
over again a certain number of times. So,
instead of adding several almost equal code-lines in a script, we can use
loops.
Loops are used to execute the same block of code again and again, as long as
a certain condition is true.
In PHP, we have the following loop types:
•while - loops through a block of code as long as the specified condition is
true
•do...while - loops through a block of code once, and then repeats the loop
as long as the specified condition is true
•for - loops through a block of code a specified number of times
•foreach - loops through a block of code for each element in an array
The following chapters will explain and give examples of each loop type.
While , Do-while Loop
$i = 0; $i = 1;
while ($i < 6) { while ($i < 6):
$i++; echo $i;
if ($i == 3) continue; $i++;
echo $i; endwhile;
}

$i = 1;

do {
echo $i;
$i++;
} while ($i < 6);
For , foreach Loop
Syntax
for (expression1, expression2, expression3) {
// code block
}
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
• GET vs. POST
• Both GET and POST create an array (e.g. array( key1 => value1, key2 => value2,
key3 => value3, ...)). This array holds key/value pairs, where keys are the names
of the form controls and values are the input data from the user.
• Both GET and POST are treated as $_GET and $_POST. These are superglobals,
which means that they are always accessible, regardless of scope - and you can
access them from any function, class or file without having to do anything
special.
• $_GET is an array of variables passed to the current script via the URL
parameters.
• $_POST is an array of variables passed to the current script via the HTTP POST
method.
• When to use GET?
Information sent from a form with the GET method is visible to everyone (all variable
names and values are displayed in the URL). GET also has limits on the amount of
information to send. The limitation is about 2000 characters. However, because the
variables are displayed in the URL, it is possible to bookmark the page. This can be
useful in some cases.
• GET may be used for sending non-sensitive data.
• Note: GET should NEVER be used for sending passwords or other sensitive
information!
• When to use POST?
Information sent from a form with the POST method is invisible to others (all
names/values are embedded within the body of the HTTP request) and has no limits on
the amount of information to send.
• Moreover POST supports advanced functionality such as support for multi-part binary
input while uploading files to server.
• However, because the variables are not displayed in the URL, it is not possible to
bookmark the page.
Juggling
• PHP is known as a dynamically typed language. Explicit type
declaration of a variable is neither needed nor supported in PHP.
• Contrary to C, C++ and Java, type of PHP variable is decided by the
value assigned to it, and not other way around.
• Further, a variable when assigned value of different type, its type too
changes.
• This approach of PHP to deal with dynamically changing value of
variable is called type juggling.
• $var="Hello"; // variable is string type
• $var=100; //same variable now becomes int
• Type juggling also takes place during calculation of expression. In this example, a
string variable containing digits is automatically converted to integer for
evaluation of addition expression
• Example
• Live Demo

<?php
$var1=100;
$var2="100";
$var3=$var1+$var2;
var_dump($var3);
?>
• $_REQUEST
What is it?
• The $_REQUEST variable is a variable with the contents of $_GET and $_POST and
$_COOKIE variables.
How to use it?
• Before you can use the $_REQUEST variable you have to have a form in html that has
the method equal to GET and POST. Then in the php, you can use the $_REQUEST
variable to get the data that you wanted. Depending on what you wrote for the
method in the form and using $_REQUEST in the php, $_REQUEST will use $_Get if
GET is written for the method and $_REQUEST will use $POST if POST is written in the
method. The $_REQUEST syntax is ($_REQUEST['name of the form field goes here’]).
• Examples
• The $_REQUEST syntax
<?php
//this will stay the same but the method in the form will change to you preference from
GET or POST
($_REQUEST['form name goes here'])
?>
• Using GET for the method
<?php
//Displays the data that was received from the input box named name in the
form
echo ($_REQUEST['name']);
?>

//This is the html form that creates the input box and submit button
//The method for the form is in the line below
<form action="test.php" method=GET>
Name:<br><input type="text" name="name"><br>
<input type="submit" value="Submit">
</form>
Using POST for the method
<?php
//Displays the data that was received from the input box named name in the form
echo ($_REQUEST['name']);
?>

//This is the html form that creates the input box and submit button
//The method for the form is in the line below
<form action="test.php" method=POST>
Name:<br><input type="text" name="name"><br>
<input type="submit" value="Submit">
</form>

You might also like