Tải bản đầy đủ (.ppt) (21 trang)

Slide môn học PHP session 3 form handling in PHP

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (260.47 KB, 21 trang )

Form Handling in PHP
Session 2


Review - I






PHP is a general purpose scripting language used for
developing dynamic web pages
PHP is developed from C-modules
PHP has become a popular tool for e-commerce
PHP 4.0 includes supportive features for the following:
 Security for user inputs
 Web servers
 New constructions for
 HTTP sessions
languages
 Output buffering

PHP / Session 3 / Slide 2 of 21


Review - II


PHP is used for generating the following:







Files in formats like PDF and HTML
Emails
Graphical images like GIF and PNG

PHP script has the following tags:
 ?>: End tag
HTTP protocol is divided into following three parts:








Request and response line
HTTP header
Body of the protocol
PHP / Session 3 / Slide 3 of 21


Review - III







header( ) function is used to generate the HTTP headers.
It sends the HTTP commands to the server through HTTP
protocols.
PHP uses tools for developing and designing web pages.
These tools are the program text editors.
Gedit is the most popular text editor used for programming
on Linux platform

PHP / Session 3 / Slide 4 of 21


Objectives





Use the GET Method
Use the POST Method
Retrieve data from forms using variables
Use hidden fields

PHP / Session 3 / Slide 5 of 21


Forms - I







Form provides medium of interface between the client
and server
PHP provides us with the powerful feature of handling
forms
PHP provides built-in support for collecting data from
a HTML form

PHP / Session 3 / Slide 6 of 21


Forms - II




On submission of the form, the information is sent
to the Web server, which in turn passes the
information to the PHP script engine
Script
engine
processes
the
information,
manipulates it, and sends the output back to the Web

browser

PHP / Session 3 / Slide 7 of 21


Forms - III


A form consists of the following attributes:
 Action: Specifies the Uniform Resource Locator
(URL) that will process the form data and send the
feedback
 Method: Specifies the method by which data is to be
sent to the URL

PHP / Session 3 / Slide 8 of 21


GET Method - I






Specifies the Web browser to send all the user
information as part of the URL
Question mark is added at the end of the URL, which
indicates the ending of the URL and the beginning of
the form information

Information on the form is transmitted in the structure
of name/value pairs to the URL

PHP / Session 3 / Slide 9 of 21


GET Method - II








Multiple name/value pairs can be sent to the URL by
separating each pair with the ampersand (&) sign
Name/value pairs are similar to variables
Once name/value are on the Web server for
processing, PHP make them available as variables
Name/value pairs sent to the URL is a query string
GET Method transmits only limited data

PHP / Session 3 / Slide 10 of 21


POST Method - I





Specifies the Web browser to send all the user
information through the body of the HTTP request
Transmits more information through the body of
the HTTP request, as there no physical limit on the
amount of information passed through the body of
the HTTP request

PHP / Session 3 / Slide 11 of 21


POST Method - II




Information sent by the POST method is not
encrypted. As a result, it is easily accessible
to a hacker.
In order to make the information to be
secure, it is necessary to establish a secure
server connection

PHP / Session 3 / Slide 12 of 21


Difference in GET and POST - I







GET method sends information through the URL
whereas the POST method sends information through
the body of the HTTP request
GET method is less secure as all the users are able to
view the transmitted information in the URL
GET method enables to transmit less amount of
information as compared to the POST

PHP / Session 3 / Slide 13 of 21


Difference in GET and POST - II




In the GET method, the pages loaded are carefully
book-marked, whereas in POST method the pages
loaded are not properly book-marked
GET method retrieves the information whereas the
POST method manipulates the information on the
Web server

PHP / Session 3 / Slide 14 of 21


Retrieving Data Using GET

Method


The syntax to retrieve the data if we have used the GET
method is:
$varname = $_GET[‘variable’];
Where,
 varname - Specifies the name of the variable in
which the data is to be stored
 _GET[‘variable’]- Specifies the name of the
input variable
PHP / Session 3 / Slide 15 of 21


Retrieving Data Using POST
Method
To retrieve the data if we have used the POST
method, the syntax is:
$varname=$_POST[‘variable’];
Where,







varname - Specifies the name of the variable in which
the data is to be stored
POST[‘variable’] - Specifies the name of the input

variable

PHP / Session 3 / Slide 16 of 21


Hidden Fields - I







Hidden form field enables to pass information to the
Web server
Hidden field is similar to the text field
The difference is that the user cannot view the hidden
field and its contents
To view whether the form contains the hidden field,
the user needs to view the HTML source code of the
form
PHP / Session 3 / Slide 17 of 21


Hidden Fields - II


The syntax to define the hidden filed is:
VALUE=”PHP MESSAGE”>

Where,
 INPUT TYPE - Specifies that the field is hidden
 NAME - Specifies the name of the hidden field
 VALUE - Specifies the value as it appears on the form

PHP / Session 3 / Slide 18 of 21


Summary - I









Form provides a medium of interaction where users can
fill in data
PHP has a built-in support for collecting data from a
HTML form
Information from the form is automatically available to
the script engine
Script engine processes the information
Server recognizes the form as a collection of codes

PHP / Session 3 / Slide 19 of 21



Summary - II








Attributes of a form as are as follows:
 Action
 Method
In order to create a Form, we use the opening and
closing <FORM> tags
Elements placed between the<FORM> tags,
automatically becomes a part of the form
The GET method specifies the browser to send the
values the user placed on the form to the URL
PHP / Session 3 / Slide 20 of 21


Summary - III






POST method informs the browser to send the values
the user placed on the form to the PHP script engine in

the body of the HTTP request
Hidden form fields enables form developers to pass
information, from a form to a script, or from one form
to another, before being passed to a script
Hidden form fields are not visible to users

PHP / Session 3 / Slide 21 of 21



×