SlideShare una empresa de Scribd logo
1 de 13
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Session Handling in Php
SWALIH T
swalihk321@gmail.com
www.facebook/ swalih321
twitter.com/swalih321
in.linkedin.com/in/swalih321
9539353663
Session
• A continuous period of access, unique to
each user that requests a PHP page from
a website
How do ‘Sessions’ work?
• Each user is assigned a unique number, or
session id, e.g.
• Session data is stored in a text file on the
server
– Filename is sess_sessionid
• Session data can be accessed through a
PHP superglobal, $_SESSION.
Starting or Resuming a Session
session_start();
• Must be called before any output to browser
• Must be called on every page that will participate
in the session
– If session_start() is not called, session data will not be
available
• No parameters
• No return value
Starting or Resuming a Session
session_start();
• PHP looks for a valid session id in the
$_COOKIE or $_GET superglobals
• If found, it loads the registered session
variables
• If none found, a new session id is created
Storing Session Data
• The $_SESSION superglobal array can be
used to store any session data.
$_SESSION['name'] = $name;
$_SESSION['age'] = $age;
Reading Session Data
• Data is simply read back from the
$_SESSION superglobal array.
$name = $_SESSION['name'];
$age = $_SESSION['age'];
Destroying a Session
Often not required, but if we want to
destroy a session:
// unset one session variable
unset($_SESSION[‘username’]);
// clear all session variables
$_SESSION = array();
// destroy session
session_destroy();
Try
• Navigate to login
• Login with username: bob, password: b123
• Copy/paste the URL to another tab in the same
browser
• Close the browser and reopen it. Does it
remember you?
• Paste the URL into another browser. What
happens
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

Más contenido relacionado

La actualidad más candente

Java servlets
Java servletsJava servlets
Java servlets
lopjuan
 

La actualidad más candente (20)

Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Arrays in PHP
Arrays in PHPArrays in PHP
Arrays in PHP
 
PHP Cookies and Sessions
PHP Cookies and SessionsPHP Cookies and Sessions
PHP Cookies and Sessions
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
Files in php
Files in phpFiles in php
Files in php
 
Php
PhpPhp
Php
 
Files and Directories in PHP
Files and Directories in PHPFiles and Directories in PHP
Files and Directories in PHP
 
Class 5 - PHP Strings
Class 5 - PHP StringsClass 5 - PHP Strings
Class 5 - PHP Strings
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Files in java
Files in javaFiles in java
Files in java
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Php forms
Php formsPhp forms
Php forms
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Java servlets
Java servletsJava servlets
Java servlets
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Php sessions
Php sessionsPhp sessions
Php sessions
 

Similar a Session handling in php

Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
Harit Kothari
 

Similar a Session handling in php (20)

7. Sessions.pptx
7. Sessions.pptx7. Sessions.pptx
7. Sessions.pptx
 
Session handling in codeigniter
Session handling in codeigniterSession handling in codeigniter
Session handling in codeigniter
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)
 
17 sessions
17 sessions17 sessions
17 sessions
 
PHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and SessionsPHP - Introduction to PHP Cookies and Sessions
PHP - Introduction to PHP Cookies and Sessions
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Ruby on Rails Security Guide
Ruby on Rails Security GuideRuby on Rails Security Guide
Ruby on Rails Security Guide
 
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
 
6 global library function provided by open cart
6 global library function provided by open cart6 global library function provided by open cart
6 global library function provided by open cart
 
Get and post,session and cookie
Get and post,session and cookieGet and post,session and cookie
Get and post,session and cookie
 
Stored procedures with cursor
Stored procedures with cursorStored procedures with cursor
Stored procedures with cursor
 
Why WordPress Works
Why WordPress WorksWhy WordPress Works
Why WordPress Works
 
Sas manager-s-guide v50-03052012
Sas manager-s-guide v50-03052012Sas manager-s-guide v50-03052012
Sas manager-s-guide v50-03052012
 
Php sessions
Php sessionsPhp sessions
Php sessions
 
Just will show some dnn administration menu options
Just will show some dnn administration menu optionsJust will show some dnn administration menu options
Just will show some dnn administration menu options
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Altspace vr overview
Altspace vr overviewAltspace vr overview
Altspace vr overview
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
 
Denver ACE March Remote Transition Tips
Denver ACE March Remote Transition TipsDenver ACE March Remote Transition Tips
Denver ACE March Remote Transition Tips
 

Más de baabtra.com - No. 1 supplier of quality freshers

Más de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 

Último

The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Último (20)

PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Session handling in php

  • 1.
  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. Session Handling in Php SWALIH T swalihk321@gmail.com www.facebook/ swalih321 twitter.com/swalih321 in.linkedin.com/in/swalih321 9539353663
  • 4. Session • A continuous period of access, unique to each user that requests a PHP page from a website
  • 5. How do ‘Sessions’ work? • Each user is assigned a unique number, or session id, e.g. • Session data is stored in a text file on the server – Filename is sess_sessionid • Session data can be accessed through a PHP superglobal, $_SESSION.
  • 6. Starting or Resuming a Session session_start(); • Must be called before any output to browser • Must be called on every page that will participate in the session – If session_start() is not called, session data will not be available • No parameters • No return value
  • 7. Starting or Resuming a Session session_start(); • PHP looks for a valid session id in the $_COOKIE or $_GET superglobals • If found, it loads the registered session variables • If none found, a new session id is created
  • 8. Storing Session Data • The $_SESSION superglobal array can be used to store any session data. $_SESSION['name'] = $name; $_SESSION['age'] = $age;
  • 9. Reading Session Data • Data is simply read back from the $_SESSION superglobal array. $name = $_SESSION['name']; $age = $_SESSION['age'];
  • 10. Destroying a Session Often not required, but if we want to destroy a session: // unset one session variable unset($_SESSION[‘username’]); // clear all session variables $_SESSION = array(); // destroy session session_destroy();
  • 11. Try • Navigate to login • Login with username: bob, password: b123 • Copy/paste the URL to another tab in the same browser • Close the browser and reopen it. Does it remember you? • Paste the URL into another browser. What happens
  • 12. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks www.baabtra.com | www.massbaab.com |www.baabte.com
  • 13. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com