SlideShare a Scribd company logo
PHP
$_GET / $_POST / $_SESSION
• PHP uses predefined variables to provide access to
important information about the server and requests
from a browser.
• PHP provides a large number of predefined variables to
any script which it runs. PHP provides an additional set
of predefined arrays containing variables from the web
server the environment, and user input.
• We can access predefined variables in any scope - any if
block, any for block. It means every where in PHP block.
• There are many predefined variables provided by PHP
but this week you will learn just $_GET, $_POST,
$_SESSION because there are common things you need
to know.
HANDLING USER
INPUT WITH $_GET / $_POST
Before knowing $_GET and $_POST
You have to know ‘HTTP data sending method’ first.
• HTTP is how webpage runs. it is agreement between web
server and web browser. That is how server and browser
communicate to each other.
• HTTP sending method is about how much secure browser
send data to server. (data which comes from user input).
- GET method is less secure but easier.
With this method we can send data by submitting form or put
it directly in address bar but web user can see datas in
address bar.
( http://webserver/calculate.php?a=10&b=5 )
- POST method is better secure but more difficult.
With this method we can send data by only submitting form
and web user cannot see datas in address bar.
( http://webserver/calculate.php )
THE WAY OF $_GET
• We have 2 ways to send data from one php
page to another one php page (or itself).
– First is using form submission.
• Important to set method=“get”
– Second is specifying data as key-value pair directly
after URL.
• When datas are sent to destination page you
will see the URL in address bar
• In destination page you can use $_GET[‘key or
name of data’]; in PHP block to access datas
sent from source page.
THE WAY OF $_POST
• We have 1 way to send data from one php
page to another one php page (or itself).
– It is using form submission.
• Important to set method=“post”
• When datas are sent to destination page you
will see the URL in address bar
• In destination page you can use $_POST[‘key or
name of data’]; in PHP block to access datas
sent from source page.
STORING USER’S STATE OR
TEMPORARY INFO WITH
$_SESSION
Before knowing $_SESSION
• Session provides a way to identify a user across more than
one page request or visit to a Web site and to store
information about that user.
• Session is like transaction, at 7-11 cashier you buy 3 things -
Lays, Coke, Mama. Cashier staff calculates the price one by
one by scanning your things’ barcode. She does three times
then press ‘Enter’ to finish to process. The whole process just
now is 1 transaction.
• The same way when you go to facebook.com website. You
may first go to your profile first then you go to your friends’
profile, leave some comments. You found your friend of
friend looks nice, you go to his/ her profile and try to see
information, photos, marriage status. You may go 5-6 pages
already but that is 1 session.
• Session may start when you first come to web site at any
page or logged in success.
• After session started, web server can store your state
(your information, your input, your IP address, Item you
want to buy etc).
• Web server can destroy your session
- by program (such as when you click logout) or
- by timing which is when you are inactive (sleep in front
your
• computer or you did not go any page within the same
web site) within defined interval (such as 30 minutes).
We call this ‘Session timeout’.
Starting a session.
• Before you can begin storing user information
in your PHP session, you must first start the
session. When you start a session, it must be
at the very beginning of your code, before any
HTML or text is sent.
• Below is a simple script that you should place
at the beginning of your PHP code to start up
a PHP session.
<?php
session_start(); // start up your PHP session!
?>
<html>
.
.
.
</html>
Storing / Getting data.
• When you want to store user data in a session
use the $_SESSION associative array. This is
where you both store and retrieve session
data.
<?php
session_start(); // start up your PHP session!
?>
<html>
<body>
<?php
$_SESSION[‘views’])=1; // store session data
print “view is =“.$_SESSION[‘views’]; // retrieve data
?>
</body>
</html>
Check if particular session data exists.
• isset() function comes in handy. isset is a
function that takes any variable you want to
use and checks to see if it has been set. That
is, it has already been assigned a value.
• With our previous example, we can create a
very simple pageview counter by using isset to
check if the pageview variable has already
been created. If it has we can increment our
counter. If it doesn't exist we can create a
pageview counter and set it to one. Here is
the code to get this job done:
<?php
session_start(); // start up your PHP session!
?>
<html>
<body>
<?php
if(isset($_SESSION[‘views’]))
$_SESSION[‘views’])= $_SESSION[‘views’]+1;
else
$_SESSION[‘views’])=1;
print “view is =“.$_SESSION[‘views’];
?>
</body>
</html>
Destroying session
• You may remove some datas in someone’s
session such as session data named ‘cart’
when shopping cart is checked out.
<?php
session_start(); // start up your PHP session!
?>
<html>
<body>
<?php
// Remove only session data name ‘cart’
if(isset($_SESSION[‘cart’])) unset($_SESSION[‘cart’]) ;
?>
</body>
</html>
• You can also destroy someone’s whole session
when he clicked log out button.
<?php
session_start(); // start up your PHP session!
?>
<html>
…
</html>
<?php
session_destroy(); // destroy your PHP session!
?>
Setting up session timeout interval.
• If you want your session of visitor to be
destroy if your visitor are inactive (did not
open any page for a while) for an interval you
desire, you can easily set it as below:
• Note that number is second. So 1800 is 30
minutes.
<?php
ini_set(‘session.gc_maxlifetime’,’1800’);
session_start(); // start up your PHP session!
?>
<html>
…
</html>

More Related Content

What's hot (20)

PPT
Parameter Passing & Session Tracking in PHP
amichoksi
 
PDF
Login and Registration form using oop in php
herat university
 
PDF
Php login system with admin features evolt
GIMT
 
PPT
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
PPTX
PHP for hacks
Tom Praison Praison
 
PPTX
Phphacku iitd
Sorabh Jain
 
PDF
Php workshop L04 database
Mohammad Tahsin Alshalabi
 
PDF
Php workshop L03 superglobals
Mohammad Tahsin Alshalabi
 
PPTX
Session php
200Hussain
 
PDF
Introduction to PHP
Bradley Holt
 
PDF
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
PPT
PHP and MySQL
webhostingguy
 
KEY
Using PHP
Mark Casias
 
PPTX
Php hacku
Tom Praison Praison
 
PPTX
18.register login
Razvan Raducanu, PhD
 
PPT
Intro to php
Sp Singh
 
PPT
Intro to PHP
Sandy Smith
 
PPT
Dance for the puppet master: G6 Tech Talk
Michael Peacock
 
Parameter Passing & Session Tracking in PHP
amichoksi
 
Login and Registration form using oop in php
herat university
 
Php login system with admin features evolt
GIMT
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
webhostingguy
 
PHP for hacks
Tom Praison Praison
 
Phphacku iitd
Sorabh Jain
 
Php workshop L04 database
Mohammad Tahsin Alshalabi
 
Php workshop L03 superglobals
Mohammad Tahsin Alshalabi
 
Session php
200Hussain
 
Introduction to PHP
Bradley Holt
 
Introduction to php web programming - get and post
baabtra.com - No. 1 supplier of quality freshers
 
PHP and MySQL
webhostingguy
 
Using PHP
Mark Casias
 
18.register login
Razvan Raducanu, PhD
 
Intro to php
Sp Singh
 
Intro to PHP
Sandy Smith
 
Dance for the puppet master: G6 Tech Talk
Michael Peacock
 

Viewers also liked (6)

PPT
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
PPT
PHP - Introduction to String Handling
Vibrant Technologies & Computers
 
PPTX
Php Form
lotlot
 
ODP
Form Processing In Php
Harit Kothari
 
PPTX
Php string function
Ravi Bhadauria
 
PDF
jQuery in 15 minutes
Simon Willison
 
PHP - Introduction to PHP Functions
Vibrant Technologies & Computers
 
PHP - Introduction to String Handling
Vibrant Technologies & Computers
 
Php Form
lotlot
 
Form Processing In Php
Harit Kothari
 
Php string function
Ravi Bhadauria
 
jQuery in 15 minutes
Simon Willison
 
Ad

Similar to php $_GET / $_POST / $_SESSION (20)

PPT
Cookies and sessions
UdaAs PaNchi
 
PPTX
Sessions in php
Mudasir Syed
 
PPT
Lecture8 php page control by okello erick
okelloerick
 
PPTX
A179178417_21_2025_PHP Get and Post.pptx
malikanuj0151
 
PPTX
Web Techniques like Cookies and Sessions
SonaliAbhang
 
PPTX
PHP SESSIONS & COOKIE.pptx
ShitalGhotekar
 
PDF
PHP-Cookies-Sessions.pdf
HumphreyOwuor1
 
PDF
Security in php
Jalpesh Vasa
 
PDF
Lecture2_IntroductionToPHP_Spring2023.pdf
ShaimaaMohamedGalal
 
PPTX
PHP COOKIES AND SESSIONS
Degu8
 
PDF
GET and POST in PHP
Vineet Kumar Saini
 
PPTX
Session,cookies and get and post methods
baabtra.com - No. 1 supplier of quality freshers
 
PPT
season management in php (WT)
kunjan shah
 
PPTX
lecture 13.pptx
ITNet
 
DOC
Php sessions
clickon2010
 
PPTX
Authentication methods
sana mateen
 
PPTX
Introduction to PHP.pptx
SherinRappai
 
PPTX
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
Cookies and sessions
UdaAs PaNchi
 
Sessions in php
Mudasir Syed
 
Lecture8 php page control by okello erick
okelloerick
 
A179178417_21_2025_PHP Get and Post.pptx
malikanuj0151
 
Web Techniques like Cookies and Sessions
SonaliAbhang
 
PHP SESSIONS & COOKIE.pptx
ShitalGhotekar
 
PHP-Cookies-Sessions.pdf
HumphreyOwuor1
 
Security in php
Jalpesh Vasa
 
Lecture2_IntroductionToPHP_Spring2023.pdf
ShaimaaMohamedGalal
 
PHP COOKIES AND SESSIONS
Degu8
 
GET and POST in PHP
Vineet Kumar Saini
 
Session,cookies and get and post methods
baabtra.com - No. 1 supplier of quality freshers
 
season management in php (WT)
kunjan shah
 
lecture 13.pptx
ITNet
 
Php sessions
clickon2010
 
Authentication methods
sana mateen
 
Introduction to PHP.pptx
SherinRappai
 
5. Formshcfsjhfajkjsfjsjfjksafjsfjkjfhjsafjsajkgfjskafkjas.pptx
berihun18
 
Ad

More from tumetr1 (20)

PDF
ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
tumetr1
 
PDF
ตัวอย่างภาคผนวก เล่มโปรเจ็ค
tumetr1
 
PDF
ตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
tumetr1
 
PDF
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
tumetr1
 
PDF
ตัวอย่างสารบัญ เล่มโปรเจ็ค
tumetr1
 
PDF
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
tumetr1
 
PDF
ตัวอย่างบทคัดย่อเล่มโปรเจ็ค
tumetr1
 
PPT
file transfer and access utilities
tumetr1
 
PPT
retrieving the mail
tumetr1
 
PPT
connectivity utility
tumetr1
 
PPT
network hardware
tumetr1
 
PPT
ระบบเครือข่ายไร้สาย (wireless lan)
tumetr1
 
PPT
routing
tumetr1
 
PPT
the transport layer
tumetr1
 
PPT
ระดับชั้นเน็ตเวิร์ก
tumetr1
 
PPT
ระดับชั้นดาต้าลิงค์
tumetr1
 
PPT
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
tumetr1
 
PPT
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
tumetr1
 
PPT
ความรู้พื้นฐานของระบบการสื่อสารข้อมูล
tumetr1
 
PPT
พัฒนาเศรษฐกิจ
tumetr1
 
ตัวอย่างประวัติผู้วิจัย เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างภาคผนวก เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างบรรณานุกรม เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างบทที่1 บทนำ เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างสารบัญ เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างกิตติกรรมประกาศ เล่มโปรเจ็ค
tumetr1
 
ตัวอย่างบทคัดย่อเล่มโปรเจ็ค
tumetr1
 
file transfer and access utilities
tumetr1
 
retrieving the mail
tumetr1
 
connectivity utility
tumetr1
 
network hardware
tumetr1
 
ระบบเครือข่ายไร้สาย (wireless lan)
tumetr1
 
routing
tumetr1
 
the transport layer
tumetr1
 
ระดับชั้นเน็ตเวิร์ก
tumetr1
 
ระดับชั้นดาต้าลิงค์
tumetr1
 
สถาปัตยกรรมเครือข่ายคอมพิวเตอร์และบริการ
tumetr1
 
การส่งข้อมูลผ่านสายส่งและเทคนิคการส่งข้อมูลผ่านเครือข่าย
tumetr1
 
ความรู้พื้นฐานของระบบการสื่อสารข้อมูล
tumetr1
 
พัฒนาเศรษฐกิจ
tumetr1
 

Recently uploaded (20)

PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
community health nursing question paper 2.pdf
Prince kumar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 

php $_GET / $_POST / $_SESSION

  • 1. PHP
  • 2. $_GET / $_POST / $_SESSION
  • 3. • PHP uses predefined variables to provide access to important information about the server and requests from a browser. • PHP provides a large number of predefined variables to any script which it runs. PHP provides an additional set of predefined arrays containing variables from the web server the environment, and user input. • We can access predefined variables in any scope - any if block, any for block. It means every where in PHP block. • There are many predefined variables provided by PHP but this week you will learn just $_GET, $_POST, $_SESSION because there are common things you need to know.
  • 4. HANDLING USER INPUT WITH $_GET / $_POST
  • 5. Before knowing $_GET and $_POST You have to know ‘HTTP data sending method’ first. • HTTP is how webpage runs. it is agreement between web server and web browser. That is how server and browser communicate to each other. • HTTP sending method is about how much secure browser send data to server. (data which comes from user input). - GET method is less secure but easier. With this method we can send data by submitting form or put it directly in address bar but web user can see datas in address bar. ( http://webserver/calculate.php?a=10&b=5 ) - POST method is better secure but more difficult. With this method we can send data by only submitting form and web user cannot see datas in address bar. ( http://webserver/calculate.php )
  • 6. THE WAY OF $_GET • We have 2 ways to send data from one php page to another one php page (or itself). – First is using form submission. • Important to set method=“get” – Second is specifying data as key-value pair directly after URL.
  • 7. • When datas are sent to destination page you will see the URL in address bar • In destination page you can use $_GET[‘key or name of data’]; in PHP block to access datas sent from source page.
  • 8. THE WAY OF $_POST • We have 1 way to send data from one php page to another one php page (or itself). – It is using form submission. • Important to set method=“post”
  • 9. • When datas are sent to destination page you will see the URL in address bar • In destination page you can use $_POST[‘key or name of data’]; in PHP block to access datas sent from source page.
  • 10. STORING USER’S STATE OR TEMPORARY INFO WITH $_SESSION
  • 11. Before knowing $_SESSION • Session provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. • Session is like transaction, at 7-11 cashier you buy 3 things - Lays, Coke, Mama. Cashier staff calculates the price one by one by scanning your things’ barcode. She does three times then press ‘Enter’ to finish to process. The whole process just now is 1 transaction. • The same way when you go to facebook.com website. You may first go to your profile first then you go to your friends’ profile, leave some comments. You found your friend of friend looks nice, you go to his/ her profile and try to see information, photos, marriage status. You may go 5-6 pages already but that is 1 session.
  • 12. • Session may start when you first come to web site at any page or logged in success. • After session started, web server can store your state (your information, your input, your IP address, Item you want to buy etc). • Web server can destroy your session - by program (such as when you click logout) or - by timing which is when you are inactive (sleep in front your • computer or you did not go any page within the same web site) within defined interval (such as 30 minutes). We call this ‘Session timeout’.
  • 13. Starting a session. • Before you can begin storing user information in your PHP session, you must first start the session. When you start a session, it must be at the very beginning of your code, before any HTML or text is sent. • Below is a simple script that you should place at the beginning of your PHP code to start up a PHP session.
  • 14. <?php session_start(); // start up your PHP session! ?> <html> . . . </html>
  • 15. Storing / Getting data. • When you want to store user data in a session use the $_SESSION associative array. This is where you both store and retrieve session data.
  • 16. <?php session_start(); // start up your PHP session! ?> <html> <body> <?php $_SESSION[‘views’])=1; // store session data print “view is =“.$_SESSION[‘views’]; // retrieve data ?> </body> </html>
  • 17. Check if particular session data exists. • isset() function comes in handy. isset is a function that takes any variable you want to use and checks to see if it has been set. That is, it has already been assigned a value. • With our previous example, we can create a very simple pageview counter by using isset to check if the pageview variable has already been created. If it has we can increment our counter. If it doesn't exist we can create a pageview counter and set it to one. Here is the code to get this job done:
  • 18. <?php session_start(); // start up your PHP session! ?> <html> <body> <?php if(isset($_SESSION[‘views’])) $_SESSION[‘views’])= $_SESSION[‘views’]+1; else $_SESSION[‘views’])=1; print “view is =“.$_SESSION[‘views’]; ?> </body> </html>
  • 19. Destroying session • You may remove some datas in someone’s session such as session data named ‘cart’ when shopping cart is checked out.
  • 20. <?php session_start(); // start up your PHP session! ?> <html> <body> <?php // Remove only session data name ‘cart’ if(isset($_SESSION[‘cart’])) unset($_SESSION[‘cart’]) ; ?> </body> </html>
  • 21. • You can also destroy someone’s whole session when he clicked log out button.
  • 22. <?php session_start(); // start up your PHP session! ?> <html> … </html> <?php session_destroy(); // destroy your PHP session! ?>
  • 23. Setting up session timeout interval. • If you want your session of visitor to be destroy if your visitor are inactive (did not open any page for a while) for an interval you desire, you can easily set it as below: • Note that number is second. So 1800 is 30 minutes.