Web Design & Development
PHP
1
Passing Data Between Pages
2
1. Passing Form Data
• Forms provide a mean of submitting information
from the client to the server.
• We can create HTML forms using <form> tag
• Method and action are the most common attributes
of <form>
3
1. Passing Form Data…
• action
– gives the URL of the application that is to receive and
process the forms data
• method
– sets the HTTP method that the browser uses to send
the form's data to the server for processing
• most common methods are POST or GET
4
1. Passing Form Data…
When to Use GET?
• You can use GET (the default method):
• If the form submission is passive (like a search engine
query), and without sensitive information.
5
1. Passing Form Data…
When to Use GET?
• When you use GET, the form data will be visible in the
page address:
• action_page.php?firstname=Mickey&lastname=Mouse
6
1. Passing Form Data…
URL where Information Get Method
is to be submitted
7
1. Passing Form Data…
Getting Name
Getting Email
8
1. Passing Form Data…
Information to be Sent
URL contains all Data that was sent from previous page
9
1. Passing Form Data…
When to Use POST?
• You should use POST:
• If the form is updating data, or includes sensitive
information (password).
• POST offers better security because the submitted data
is not visible in the page address.
10
1. Passing form data…
Post method:
– Information sent will be invisible to others
– When using sensitive data such as passwords, use
Post Method.
11
1. Passing Form Data…
URL where Information Get Method
is to be submitted
12
1. Passing Form Data…
Getting Posted Name
Getting Posted Email
13
1. Passing Form Data…
Information to be Sent
URL contains no Data that was sent from previous page
14
1.1 Super Global Variables
Several predefined variables in PHP 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.
15
1.1 Super Global Variables
• PHP automatically makes few variables available in your
program
• These are array variables and can be accessed by name
• These variables are called super-global variables because
they can be accessed without regard to scope
16
2.1 Passing Text Field Data
Post Method
Text Field Text Field Name
17
2.1 Passing Text Field Data…
Display A Message
Data Received
18
2.1 Passing Text Field Data…
Form Page
Action Page
19
2.2 Passing Hidden Field Data…
Hidden Value
Hidden Field Field Name
20
2.2 Passing Hidden Field Data…
Accessing Hidden Value
21
2.2 Passing Hidden Field Data…
No Third Entry
Hidden Field Data
22
2.3 Getting Value From Checkbox
CheckBox Name Value
23
2.3 Getting Value From Checkbox
PHP Value
ASP Value
24
2.3 Getting Value From Checkbox…
25
2.3 Getting Value From Checkbox…
Checking for Value of PHP
26
2.4 Getting Value From Radio Button
Same Name
Value Set
Value Not Set
Getting Value from Radio Button
27
2.4 Getting Value From Radio Button…
28
2.5 Getting Value From Select List
Name of List
Option and Value
Getting Value of List
29
2.5 Getting Value From Select List…
30
3. Passing Variables Using Sessions
A session is basically a temporary set of variables that
exists only until the browser has shut down
• $_SESSION:
– represents data available to a PHP script that has
previously been stored in a session
31
3. Passing Variables Using Sessions
First Page
<?php
$_SESSION[‘name ‘] =‘Tehseen’; nth page
?>
<?php
echo $_SESSION[‘name ‘];
echo $_SESSION[‘email ‘];
?>
2nd Page
<?php
echo $_SESSION[‘name ‘];
$_SESSION[‘email ‘] =
‘tehseen.abbasi@comsats.edu.pk’;
?>
32
3. Passing Variables Using Sessions
session_start()
– is used to start a session
$_SESSION[‘variable_name’]
– is used to store data in session variable
session_destroy()
– is used to destroy a session
unset($_SESSION[‘variable_name’])
– is used to unset a specific variable
33
3. Passing Variables Using Sessions…
Session Starts
Session Variable Created
Link to Next Page
34
3. Passing Variables Using Sessions…
Session Starts
Session Variable Created
Link Page
35
3. Passing variables using sessions…
Session Variable’s Value
36
3. Passing variables using sessions…
Destroying Session
Accessing Session
37
3. Passing variables using sessions…
Session Accessed
Session Destroyed
38
THANK YOU
39