PHP Function: Built-in Functions part 11

Session-Handling Functions
Session handling is a way of holding on to data as a user navigates your Web Site. Data can be variables or entire objects.

session_start()
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:

session_start();

session_register()
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

session_register(“variable_name”);

For example, to register $username as a global session variable, use this:

session_register(“username”);

session_unregister()
function unregisters, or “forgets,” a variable within the current session. Its syntax is

session_unregister(“variable_name”);

For example, to forget about the global session variable called $username, use this:

session_unregister(“username”);

session_destroy()
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:

session_destroy();

Next php function: Built-in Functions part 12