SlideShare a Scribd company logo
1 of 24
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)

Parameter Passing & Session Tracking in PHP
Parameter Passing & Session Tracking in PHPParameter Passing & Session Tracking in PHP
Parameter Passing & Session Tracking in PHP
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
 
Php login system with admin features evolt
Php login system with admin features   evoltPhp login system with admin features   evolt
Php login system with admin features evolt
 
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...PHP and MySQL PHP Written as a set of CGI binaries in C in ...
PHP and MySQL PHP Written as a set of CGI binaries in C in ...
 
PHP for hacks
PHP for hacksPHP for hacks
PHP for hacks
 
Phphacku iitd
Phphacku iitdPhphacku iitd
Phphacku iitd
 
Php workshop L04 database
Php workshop L04 databasePhp workshop L04 database
Php workshop L04 database
 
Php workshop L03 superglobals
Php workshop L03 superglobalsPhp workshop L03 superglobals
Php workshop L03 superglobals
 
Session php
Session phpSession php
Session php
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Sa
SaSa
Sa
 
Introduction to php web programming - get and post
Introduction to php  web programming - get and postIntroduction to php  web programming - get and post
Introduction to php web programming - get and post
 
Session handling in php
Session handling in phpSession handling in php
Session handling in php
 
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Using PHP
Using PHPUsing PHP
Using PHP
 
Php hacku
Php hackuPhp hacku
Php hacku
 
18.register login
18.register login18.register login
18.register login
 
Intro to php
Intro to phpIntro to php
Intro to php
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
Dance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech TalkDance for the puppet master: G6 Tech Talk
Dance for the puppet master: G6 Tech Talk
 

Viewers also liked

Viewers also liked (6)

PHP - Introduction to PHP Functions
PHP -  Introduction to PHP FunctionsPHP -  Introduction to PHP Functions
PHP - Introduction to PHP Functions
 
PHP - Introduction to String Handling
PHP -  Introduction to  String Handling PHP -  Introduction to  String Handling
PHP - Introduction to String Handling
 
Php Form
Php FormPhp Form
Php Form
 
Form Processing In Php
Form Processing In PhpForm Processing In Php
Form Processing In Php
 
Php string function
Php string function Php string function
Php string function
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 

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

Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Sessions in php
Sessions in php Sessions in php
Sessions in php
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
PHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptxPHP SESSIONS & COOKIE.pptx
PHP SESSIONS & COOKIE.pptx
 
PHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdfPHP-Cookies-Sessions.pdf
PHP-Cookies-Sessions.pdf
 
Security in php
Security in phpSecurity in php
Security in php
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Lecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdfLecture2_IntroductionToPHP_Spring2023.pdf
Lecture2_IntroductionToPHP_Spring2023.pdf
 
PHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONS
 
GET and POST in PHP
GET and POST in PHPGET and POST in PHP
GET and POST in PHP
 
Session,cookies and get and post methods
Session,cookies  and get and post methodsSession,cookies  and get and post methods
Session,cookies and get and post methods
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)
 
lecture 13.pptx
lecture 13.pptxlecture 13.pptx
lecture 13.pptx
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php sessions
Php sessionsPhp sessions
Php sessions
 
Authentication methods
Authentication methodsAuthentication methods
Authentication methods
 
Introduction to PHP.pptx
Introduction to PHP.pptxIntroduction to PHP.pptx
Introduction to PHP.pptx
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
 
Php file upload, cookies & session
Php file upload, cookies & sessionPhp file upload, cookies & session
Php file upload, cookies & session
 
Php session
Php sessionPhp session
Php session
 

More from tumetr1

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

More from tumetr1 (20)

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

Recently uploaded

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

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.