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

Session handling in php

  • 2.
    Disclaimer: This presentationis 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 inPhp SWALIH T swalihk321@gmail.com www.facebook/ swalih321 twitter.com/swalih321 in.linkedin.com/in/swalih321 9539353663
  • 4.
    Session • A continuousperiod 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 Resuminga 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 Resuminga 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 Oftennot 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 tologin • 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 presentationhelped 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