In PHP, a session is a way to store information (in variables) to be used across multiple pages. ,
Web browsers and Web servers have a stateless interaction and do not maintain track of user sessions
Enables Web browsers to communicate with Web servers
Has no methods or functions to maintain the status of a particular user
WHAT IS A PHP SESSION?
In PHP, When you work with an application, you open it, do some changes, and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the Internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn’t maintain state.
In PHP, Session variables solve this problem by storing user information to be used across multiple pages (e.g username, favorite color, etc). By default, session variables last until the user closes the browser.
So; Session variables hold information about one single user, and are available to all pages in one application.
START A PHP SESSION
In PHP, A session is started with the session_start() function.
In PHP, Session variables are set with the PHP global variable:
Note: The session_start() function must be the very first thing in your document. Before any HTML tags.
DESTROY A PHP SESSION
To remove all global session variables and destroy the session,
session_unset() — remove all session variables
session_destroy() — destroy the session
Session In PHP
In PHP, Web sites that cannot depend on HTTP or Web servers for complex user interaction need session tracking
Refers to the total time the user accesses information on a particular Web site before exiting the Web site
Manages data for a particular user in a specific session
Enable distinguishing user specific information for the entire duration of the session
IMPORTANCE OF A SESSION
Consider an example, in a particular Web site, the user has to first register and then log on to access any information lit
For such authentication procedures, the state of the user has to be maintained across the Web site
Web sites traditionally use GET and POST methods to pass user information from one script to another
When these methods are used, PHP assigns user information variables in the following format:
$name = $ GET [ ‘ name 1;
In the code, the variable $name stores the value that the script retrieves from the HTML form
This process of transferring user information is time consuming and not essential for large Web sites