Session handling is a way of holding on to data as a user navigates your Web Site. Data can be variables or entire objects.
The session_start() function starts a session if one has not already been started, or it resumes a session if the session ID is present for the user. This function takes no arguments and is called simply by placing the following at the beginning of your code:
The session_register() function registers a variable within the current session. In other words, if you want to keep track of the value of a variable called $username within a user’s session, you mush first register $username as a session variable. Its syntax is
For example, to register $username as a global session variable, use this:
function unregisters, or “forgets,” a variable within the current session. Its syntax is
For example, to forget about the global session variable called $username, use this:
The session_destroy() function effectively destroys all the variables and values registered for the current session. This function takes no arguments and is called simply by placing the following in your code: