SlideShare a Scribd company logo
http://programmerblog.net
How to work with sessions and cookies in PHP
Session Handling by http://programmerblog.net
 What Is Session Handling?
 The Hypertext Transfer Protocol (HTTP) defines the rules used to transfer text, graphics, video, and all other
data via the World Wide Web
 It is a stateless protocol, meaning that each request is processed without any knowledge of any prior or
future requests
 A cookie is a small bit of information stored on a viewer's computer by his or her web browser by request
from a web page.
 The information is constantly passed in HTTP headers between the browser and web server; the browser
sends the current cookie as part of its request to the server and the server sends updates to the data back
to the user as part of its response.
 limitations on cookie size and the number of cookies allowed, and various inconveniences surrounding their
implementation, prompted developers to devise another solution: session handling.
 Session handling is essentially a clever workaround to this problem of statelessness. This
 is accomplished by assigning each site visitor a unique identifying attribute, known as the
 session ID (SID),
 Cookies
 One ingenious means for managing user information actually builds upon the original method of using a
cookie.
 When a user visits a Web site, the server stores information about the user, such as their preferences, in a
cookie and sends it to the browser, which saves it
Session Handling by http://programmerblog.net
 When a user visits a Web site, the server stores information about the user, such as their preferences, in a
cookie and sends it to the browser, which saves it
 The second method used for SID propagation simply involves appending the SID to every local URL found
within the requested page. This results in automatic SID propagation whenever the user clicks one of those
local links. This method, known as URL rewriting.
 Drawbacks
 First, URL rewriting does not allow for persistence between sessions.
 nothing stops a user from copying that URL into an e-mail and sending it to another user; as long as the
session has not expired
Session by http://programmerblog.net
 The Session-Handling Process
 PHP can be configured to autonomously control the entire session-handling process
 The very first task executed by a session-enabled page is to determine whether a valid session already
exists or a new one should be initiated.
 Configuration Directives
 Twenty-five session configuration directives are responsible for determining the behavior of PHP’s session-
handling functionality.
 session.save_handler (files, mm, sqlite, user)
 The session.save_handler directive determines how the session information will be stored.
– Default value: files
 session.save_path (string) Default value: /tmp
 If session.save_handler is set to the files storage option, then the session.save_path directive must point to
the storage directory.
 session.name (string) Default value: PHPSESSID
 session.auto_start (0|1)
 session.gc_maxlifetime (integer)
Session by http://programmerblog.net
 Starting a Session
 session_start()
 boolean session_start() –
– session_start();
 Destroying a Session
 session_unset()
 void session_unset()
 The session_unset() function erases all session variables stored in the current session,
 Note that this will not completely remove the session from the storage mechanism.
 session_destroy()
 boolean session_destroy()
 The function session_destroy() invalidates the current session by completely removing the session from the
storage mechanism.
 Retrieving and Setting the Session ID
 session_id()
 string session_id ([string sid])
 The function session_id() can both set and get the SID. If it is passed no parameter, the function
 session_id() returns the current SID.
Session by http://programmerblog.net
 session_id()
 string session_id ([string sid])
 The function session_id() can both set and get the SID. If it is passed no parameter, the function
session_id() returns the current SID.
 echo "Your session identification number is ".session_id();
 Creating and Deleting Session Variables
 It was once common practice to create and delete session variables via the functions session_register() and
session_unregister(), respectively.
 However, the preferred method involves simply setting and deleting these variable just like any other, except
that you need to refer to it in the context of the $_SESSION superglobal.
 session_start();
 $_SESSION['username'] = "jason";
 echo "Your username is ".$_SESSION['username'].".";
 unset($_SESSION['username']);
 echo "Username now set to: ".$_SESSION['username'].".";
 Encoding and Decoding Session Data
 PHP stores session data in a standardized format consisting of a single string. For example, the contents of
a session consisting of two variables, namely
 username and loggedon, is displayed here:
 username|s:5:"jason";loggedon|s:20:"Feb 16 2006 22:32:29";
Sessions by http://programmerblog.net
 Each session variable reference is separated by a semicolon, and consists of three components: the name,
length, and value.
 name|s:length:"value";
 session_encode()
 session_start();
 // Set the variables. These could be set via an HTML form, for example.
 $_SESSION['username'] = "jason";
 $_SESSION['loggedon'] = date("M d Y H:i:s");
 // Encode all session data into a single string and return the result
 $sessionVars = session_encode();
 echo $sessionVars;
 session_decode()
 session_decode($sessionVars);
 echo "User ".$_SESSION['username']." logged on at ".$_SESSION['loggedon'].".";
Cookies by http://programmerblog.net
 Cookies
 Cookies allow your applications to store a small amount of textual data (typically,
 4-6kB) on a Web client. There are a number of possible uses for cookies, although
 their most common one is maintaining session state
 To set a cookie on the client, you can use the setcookie() function:
 setcookie(“userid", “1");
 This simple function call sets a cookie called “” to a value of 1 for the remainder of the users browser
session, at which time it is automatically deleted.
 To make a cookie persist between browser sessions, you will need to provide an expiration date.
 Expiration dates are provided to setcookie() in the UNIX timestamp format (the number of seconds that have
passed since January 1, 1970)
 setcookie(“userid`", "1", time() + 86400);
 There are threemore arguments you can pass to setcookie(). They are, in order 
 path—allows you to specify a path (relative to your website’s root) where the
 cookie will be accessible; the browser will only send a cookie to pages within this path.
 domain—allows you to limit access to the cookie to pages within a specific domain or hostname; note that
you cannot set this value to a domain other than the one of the page setting the cookie (e.g.: the host
www.phparch.com can set a
 cookie for hades.phparch.com, but not for www.microsoft.com).
 • secure—this requests that the browser only send this cookie as part of its request
 headers when communicating under HTTPS.
Cookies by http://programmerblog.net

Accessing Cookie Data
 PHP places cookies in the $_COOKIE superglobal array.
 if ($_COOKIE[’hide_menu’] == 1) {
// hide menu
}
Cookie values must be scalar; of course, you can create arrays using the same array
 notation that we used for $_GET and $_POST:
 setcookie("test_cookie[0]", "foo");
 setcookie("test_cookie[1]", "bar");
 setcookie("test_cookie[2]", "bar");
 $_COOKIE[’test_cookie’] will automatically contain an array.
 You should, however, keep in mind that the amount of storage available is severely
 limited—therefore, you should keep the amount of data you store in cookies to a
 minimum, and use sessions instead.
 Deleting a Cookie
 There is no way to “delete” a cookie—primarily because you really have no control
 over how cookies are stored and managed on the client side.
setcookie with an empty string, or in pas date which will effectively reset the cookie.
 setcookie("hide_menu", false, -3600);
Cookies by http://programmerblog.net

Accessing Cookie Data
 PHP places cookies in the $_COOKIE superglobal array.
 if ($_COOKIE[’hide_menu’] == 1) {
// hide menu
}
Cookie values must be scalar; of course, you can create arrays using the same array
 notation that we used for $_GET and $_POST:
 setcookie("test_cookie[0]", "foo");
 setcookie("test_cookie[1]", "bar");
 setcookie("test_cookie[2]", "bar");
 $_COOKIE[’test_cookie’] will automatically contain an array.
 You should, however, keep in mind that the amount of storage available is severely
 limited—therefore, you should keep the amount of data you store in cookies to a
 minimum, and use sessions instead.
 Deleting a Cookie
 There is no way to “delete” a cookie—primarily because you really have no control
 over how cookies are stored and managed on the client side.
setcookie with an empty string, or in pas date which will effectively reset the cookie.
 setcookie("hide_menu", false, -3600);

More Related Content

What's hot (20)

PPSX
Sessions and cookies
www.netgains.org
 
PPT
Php Sessoins N Cookies
mussawir20
 
PPSX
Php session
argusacademy
 
PPT
Cookies & Session
university of education,Lahore
 
PPT
Cookies and sessions
UdaAs PaNchi
 
PPT
PHP Cookies, Sessions and Authentication
Gerard Sychay
 
PPTX
Session and Cookies
Kamal Acharya
 
PPTX
Cookie & Session In ASP.NET
ShingalaKrupa
 
PPTX
Cookies and sessions
Sukrit Gupta
 
PPT
Lecture8 php page control by okello erick
okelloerick
 
PPTX
Cookies and Session
KoraStats
 
PPTX
Session php
200Hussain
 
PDF
ASP.NET-Web Programming - Sessions and Cookies
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Cookies and sessions
Lena Petsenchuk
 
PPTX
Cookies in PHP
Ashok Kumar
 
PPTX
java Cookies
Rajanivetha G
 
PPT
Manish
Manish Jain
 
PPT
Web Cookies
apwebco
 
PPTX
Cookies
amuthadeepa
 
Sessions and cookies
www.netgains.org
 
Php Sessoins N Cookies
mussawir20
 
Php session
argusacademy
 
Cookies and sessions
UdaAs PaNchi
 
PHP Cookies, Sessions and Authentication
Gerard Sychay
 
Session and Cookies
Kamal Acharya
 
Cookie & Session In ASP.NET
ShingalaKrupa
 
Cookies and sessions
Sukrit Gupta
 
Lecture8 php page control by okello erick
okelloerick
 
Cookies and Session
KoraStats
 
Session php
200Hussain
 
ASP.NET-Web Programming - Sessions and Cookies
baabtra.com - No. 1 supplier of quality freshers
 
Cookies and sessions
Lena Petsenchuk
 
Cookies in PHP
Ashok Kumar
 
java Cookies
Rajanivetha G
 
Manish
Manish Jain
 
Web Cookies
apwebco
 
Cookies
amuthadeepa
 

Viewers also liked (12)

PPT
Php - Getting good with session
Firdaus Adib
 
PDF
Session and Cookie
Warawut
 
PPTX
Php session 3 Important topics
mohamedsaad24
 
PPT
Chapter 08 php advance
Dhani Ahmad
 
PPTX
Php string function
Ravi Bhadauria
 
PPTX
Cookies!
kellimccabe
 
PPTX
Cookies PowerPoint
emurfield
 
PPTX
Introduction to Web Architecture
Chamnap Chhorn
 
ODP
Session por nieves
Saregune Multimedia
 
PDF
Slides For Operating System Concepts By Silberschatz Galvin And Gagne
sarankumar4445
 
Php - Getting good with session
Firdaus Adib
 
Session and Cookie
Warawut
 
Php session 3 Important topics
mohamedsaad24
 
Chapter 08 php advance
Dhani Ahmad
 
Php string function
Ravi Bhadauria
 
Cookies!
kellimccabe
 
Cookies PowerPoint
emurfield
 
Introduction to Web Architecture
Chamnap Chhorn
 
Session por nieves
Saregune Multimedia
 
Slides For Operating System Concepts By Silberschatz Galvin And Gagne
sarankumar4445
 
Ad

Similar to Php ssession - cookies -introduction (20)

PDF
PHP-Cookies-Sessions.pdf
HumphreyOwuor1
 
PPTX
Authentication in Svelte using cookies.pptx
Knoldus Inc.
 
PPTX
PHP COOKIES AND SESSIONS
Degu8
 
PPTX
19_JavaScript - Storage_Cookies-tutorial .pptx
ssuser4a97d3
 
PPT
Session,cookies
rkmourya511
 
PPT
season management in php (WT)
kunjan shah
 
PDF
Jsp session tracking
rvarshneyp
 
PDF
S8-Session Managment
zakieh alizadeh
 
PPT
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
SreejithVP7
 
PPT
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
pondypaiyan
 
PPT
Ecom2
Santosh Pandey
 
PDF
4.4 PHP Session
Jalpesh Vasa
 
PPTX
PHP SESSIONS & COOKIE.pptx
ShitalGhotekar
 
PPTX
Session tracking In Java
honeyvachharajani
 
PPTX
4 php-advanced
Achchuthan Yogarajah
 
PDF
Cookies and sessions
salissal
 
PPTX
lecture 12.pptx
ITNet
 
PPTX
Session tracking in servlets
vishal choudhary
 
PDF
Sea surfing in asp.net mvc
magda3695
 
PDF
Web app development_cookies_sessions_14
Hassen Poreya
 
PHP-Cookies-Sessions.pdf
HumphreyOwuor1
 
Authentication in Svelte using cookies.pptx
Knoldus Inc.
 
PHP COOKIES AND SESSIONS
Degu8
 
19_JavaScript - Storage_Cookies-tutorial .pptx
ssuser4a97d3
 
Session,cookies
rkmourya511
 
season management in php (WT)
kunjan shah
 
Jsp session tracking
rvarshneyp
 
S8-Session Managment
zakieh alizadeh
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
SreejithVP7
 
Lecture 11 - PHP - Part 5 - CookiesSessions.ppt
pondypaiyan
 
4.4 PHP Session
Jalpesh Vasa
 
PHP SESSIONS & COOKIE.pptx
ShitalGhotekar
 
Session tracking In Java
honeyvachharajani
 
4 php-advanced
Achchuthan Yogarajah
 
Cookies and sessions
salissal
 
lecture 12.pptx
ITNet
 
Session tracking in servlets
vishal choudhary
 
Sea surfing in asp.net mvc
magda3695
 
Web app development_cookies_sessions_14
Hassen Poreya
 
Ad

Recently uploaded (20)

PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Human Resources Information System (HRIS)
Amity University, Patna
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 

Php ssession - cookies -introduction

  • 2. Session Handling by http://programmerblog.net  What Is Session Handling?  The Hypertext Transfer Protocol (HTTP) defines the rules used to transfer text, graphics, video, and all other data via the World Wide Web  It is a stateless protocol, meaning that each request is processed without any knowledge of any prior or future requests  A cookie is a small bit of information stored on a viewer's computer by his or her web browser by request from a web page.  The information is constantly passed in HTTP headers between the browser and web server; the browser sends the current cookie as part of its request to the server and the server sends updates to the data back to the user as part of its response.  limitations on cookie size and the number of cookies allowed, and various inconveniences surrounding their implementation, prompted developers to devise another solution: session handling.  Session handling is essentially a clever workaround to this problem of statelessness. This  is accomplished by assigning each site visitor a unique identifying attribute, known as the  session ID (SID),  Cookies  One ingenious means for managing user information actually builds upon the original method of using a cookie.  When a user visits a Web site, the server stores information about the user, such as their preferences, in a cookie and sends it to the browser, which saves it
  • 3. Session Handling by http://programmerblog.net  When a user visits a Web site, the server stores information about the user, such as their preferences, in a cookie and sends it to the browser, which saves it  The second method used for SID propagation simply involves appending the SID to every local URL found within the requested page. This results in automatic SID propagation whenever the user clicks one of those local links. This method, known as URL rewriting.  Drawbacks  First, URL rewriting does not allow for persistence between sessions.  nothing stops a user from copying that URL into an e-mail and sending it to another user; as long as the session has not expired
  • 4. Session by http://programmerblog.net  The Session-Handling Process  PHP can be configured to autonomously control the entire session-handling process  The very first task executed by a session-enabled page is to determine whether a valid session already exists or a new one should be initiated.  Configuration Directives  Twenty-five session configuration directives are responsible for determining the behavior of PHP’s session- handling functionality.  session.save_handler (files, mm, sqlite, user)  The session.save_handler directive determines how the session information will be stored. – Default value: files  session.save_path (string) Default value: /tmp  If session.save_handler is set to the files storage option, then the session.save_path directive must point to the storage directory.  session.name (string) Default value: PHPSESSID  session.auto_start (0|1)  session.gc_maxlifetime (integer)
  • 5. Session by http://programmerblog.net  Starting a Session  session_start()  boolean session_start() – – session_start();  Destroying a Session  session_unset()  void session_unset()  The session_unset() function erases all session variables stored in the current session,  Note that this will not completely remove the session from the storage mechanism.  session_destroy()  boolean session_destroy()  The function session_destroy() invalidates the current session by completely removing the session from the storage mechanism.  Retrieving and Setting the Session ID  session_id()  string session_id ([string sid])  The function session_id() can both set and get the SID. If it is passed no parameter, the function  session_id() returns the current SID.
  • 6. Session by http://programmerblog.net  session_id()  string session_id ([string sid])  The function session_id() can both set and get the SID. If it is passed no parameter, the function session_id() returns the current SID.  echo "Your session identification number is ".session_id();  Creating and Deleting Session Variables  It was once common practice to create and delete session variables via the functions session_register() and session_unregister(), respectively.  However, the preferred method involves simply setting and deleting these variable just like any other, except that you need to refer to it in the context of the $_SESSION superglobal.  session_start();  $_SESSION['username'] = "jason";  echo "Your username is ".$_SESSION['username'].".";  unset($_SESSION['username']);  echo "Username now set to: ".$_SESSION['username'].".";  Encoding and Decoding Session Data  PHP stores session data in a standardized format consisting of a single string. For example, the contents of a session consisting of two variables, namely  username and loggedon, is displayed here:  username|s:5:"jason";loggedon|s:20:"Feb 16 2006 22:32:29";
  • 7. Sessions by http://programmerblog.net  Each session variable reference is separated by a semicolon, and consists of three components: the name, length, and value.  name|s:length:"value";  session_encode()  session_start();  // Set the variables. These could be set via an HTML form, for example.  $_SESSION['username'] = "jason";  $_SESSION['loggedon'] = date("M d Y H:i:s");  // Encode all session data into a single string and return the result  $sessionVars = session_encode();  echo $sessionVars;  session_decode()  session_decode($sessionVars);  echo "User ".$_SESSION['username']." logged on at ".$_SESSION['loggedon'].".";
  • 8. Cookies by http://programmerblog.net  Cookies  Cookies allow your applications to store a small amount of textual data (typically,  4-6kB) on a Web client. There are a number of possible uses for cookies, although  their most common one is maintaining session state  To set a cookie on the client, you can use the setcookie() function:  setcookie(“userid", “1");  This simple function call sets a cookie called “” to a value of 1 for the remainder of the users browser session, at which time it is automatically deleted.  To make a cookie persist between browser sessions, you will need to provide an expiration date.  Expiration dates are provided to setcookie() in the UNIX timestamp format (the number of seconds that have passed since January 1, 1970)  setcookie(“userid`", "1", time() + 86400);  There are threemore arguments you can pass to setcookie(). They are, in order  path—allows you to specify a path (relative to your website’s root) where the  cookie will be accessible; the browser will only send a cookie to pages within this path.  domain—allows you to limit access to the cookie to pages within a specific domain or hostname; note that you cannot set this value to a domain other than the one of the page setting the cookie (e.g.: the host www.phparch.com can set a  cookie for hades.phparch.com, but not for www.microsoft.com).  • secure—this requests that the browser only send this cookie as part of its request  headers when communicating under HTTPS.
  • 9. Cookies by http://programmerblog.net  Accessing Cookie Data  PHP places cookies in the $_COOKIE superglobal array.  if ($_COOKIE[’hide_menu’] == 1) { // hide menu } Cookie values must be scalar; of course, you can create arrays using the same array  notation that we used for $_GET and $_POST:  setcookie("test_cookie[0]", "foo");  setcookie("test_cookie[1]", "bar");  setcookie("test_cookie[2]", "bar");  $_COOKIE[’test_cookie’] will automatically contain an array.  You should, however, keep in mind that the amount of storage available is severely  limited—therefore, you should keep the amount of data you store in cookies to a  minimum, and use sessions instead.  Deleting a Cookie  There is no way to “delete” a cookie—primarily because you really have no control  over how cookies are stored and managed on the client side. setcookie with an empty string, or in pas date which will effectively reset the cookie.  setcookie("hide_menu", false, -3600);
  • 10. Cookies by http://programmerblog.net  Accessing Cookie Data  PHP places cookies in the $_COOKIE superglobal array.  if ($_COOKIE[’hide_menu’] == 1) { // hide menu } Cookie values must be scalar; of course, you can create arrays using the same array  notation that we used for $_GET and $_POST:  setcookie("test_cookie[0]", "foo");  setcookie("test_cookie[1]", "bar");  setcookie("test_cookie[2]", "bar");  $_COOKIE[’test_cookie’] will automatically contain an array.  You should, however, keep in mind that the amount of storage available is severely  limited—therefore, you should keep the amount of data you store in cookies to a  minimum, and use sessions instead.  Deleting a Cookie  There is no way to “delete” a cookie—primarily because you really have no control  over how cookies are stored and managed on the client side. setcookie with an empty string, or in pas date which will effectively reset the cookie.  setcookie("hide_menu", false, -3600);