Download presentation
Presentation is loading. Please wait.
1
SESSION TRACKING BY DINESH KUMAR.R
2
What is a session? A session is a conversion between the server and a client. A conversion consists series of continuous request and response. >In computing, a session is the period of activity between a user logging in and logging out of a (multi-user) system
3
Why should a session be maintained?
When there is a series of continuous request and response from a same client to a server, the server cannot identify from which client it is getting requests. Because HTTP is a stateless protocol. When there is a need to maintain the conversational state, session tracking is needed Solution is, when a client makes a request it should introduce itself by providing unique identifier every time. There are five different methods to achieve this.
4
Session tracking methods:
User authorization Hidden fields URL rewriting Cookies Session tracking API
5
Session Functions session_name — Get and/or set the current session name session_regenerate_id — Update the current session id with a newly generated one session_decode — Decodes session data from a string session_destroy — Destroys all data registered to a session session_encode — Encodes the current session data as a string
6
Contd. session_register — Register one or more global variables with the current session session_set_save_handler — Sets user-level session storage functions session_start — Initialize session data session_unregister — Unregister a global variable from the current session session_unset — Free all session variables
7
Session STARTING Before storing user information in a PHP session, a session is to be started using session_start() function This must be at the very beginning of the code, before any HTML or text is sent. This function first checks if a session is already started and if none is started then it starts one Session variables are stored in an associative array called $_SESSION[]. These variables can be accessed during lifetime of a session.
8
CREATING SESSION VARIABLE
A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application. The correct way to store and retrieve session variables is to use the PHP $_SESSION variable. $_SESSION[‘ ‘]; date; Using array();
9
DESTROY SESSION & DELETE
session_destroy — Destroys all data registered to a session SESSION_DESTROY(); The unset() function is used to free the specified session variable: session_unset — Free sepecified session variables SESSION_UNSET();
10
session_is_registered() checks whether or not a variable has been registered.
Its syntax is: boolean session_is_registered (string varname) is_registered(); session_unregister — Unregister a global variable from the current session Eg:sessionunreg();
11
isset() Function Before using a session variable, check if it exists already isset is a function that takes any variable you want to use and checks to see if it has been set. That is, whether it has already been assigned a value. Isset();
12
session_set_save_handler — Sets user-level session storage functions
session_encode — Encodes the current session data as a string Encode(); session_decode — Decodes session data from a string Eg:sessiondecode();
13
session_name — Get and/or set the current session name
Eg. Session_name(); session_regenerate_id — Update the current session id with a newly generated one Eg.Session regenare();
14
Thank u
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.