PHP Sessions
Other than using the GET method to associate an ID to a web page, several methods can be used to achieve this function like
- Session, which is a way to store information (in variables) to be used across multiple pages,
- Cookie, which is a small file that the server embeds on the user’s computer,
- HTML hidden attribute, which is used to keep a user from seeing an element until some other condition has been met (like retrieving the user ID), and
- GET method, which is used to request data from a specified resource.
When you are working 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 and what you do because the HTTP address doesn’t maintain state.
A PHP session solves this problem by storing user information such as ID and name on the server for later use.
However, session information is temporary and will be deleted after the user has left the website.
PHP Session Variables
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.
If you need a permanent storage you may want to store the data in a database.
Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID.
The UID is either stored in a cookie or is propagated in the URL.