Session Handling - PHP

boolean session_destroy()
The session_destroy function eliminates all the data stored in the session. It does not destroy the session itself, however.

string session_encode()
The session_encode function returns a string that contains encoded information about the current session.

string session_id(string id)
Use session_id to get the value of the session identifier. If you wish to change the session identifier, supply the optional id argument. If you do, take care to do so before any output is sent to the browser, because the identifier is sent as a cookie.

boolean session_is_registered(string name)
The session_is_registered function returns TRUE if the specified variable is registered with the session.

string session_module_name(string name)
The session_module_name function returns the name of the module that handles session duties. This is the same value set by the session.save_handler directive inside php.ini. You can change the module name if you supply the optional name argument, but the only one available at the time of writing was the files module. If you wish to implement your own handler in PHP, see the
session_set_save_handler function.

string session_name(string name)
The session_name function returns the current name for the session variable. The session may be renamed with the optional name argument. This name is used as the name of the cookie that contains the session identifier. It's also used for the back-up GET variable. Consequently, if you wish to override the name of the session defined in php.ini, you must do so prior to registering any variables or starting the session.

boolean session_register(...)
The session_register function accepts any number of arguments, each of which may be a string or an array. Each argument names a global variable that will be attached to the session. Arrays passed as arguments will be traversed for elements. You can even pass multidimensional arrays. Each registered variable that is set when the script ends will be serialized and written into the session information. When the user returns with a later request, the variables will be restored.

string session_save_path(string path)
The session_save_path function returns the path in the file system used to save serialized session information. This is /tmp by default. The optional path argument will change the path. Keep in mind, the permissions for this directory must include read/write access for the Web server.

session_set_save_handler(string open, string close, stringread, string write, string destroy, string garbage)
The session_set_save_handler function allows you to implement an alternative method for handling sessions. Each argument is the name of a function for handling a certain aspect of the session handling process. Unfortunately, at the time of this writing the code that implements this functionality was not finished. Consequently, I can describe the expected arguments, but I can't provide a working example.

boolean session_start()
Use session_start to activate a session. If no session exists, one will be created. Since this involves sending a cookie, you must call session_start before sending any text to the browser. You can avoid using this function by configuring PHP to automatically start sessions with each request. This is done with the session.auto_start directive in php.ini.Once you start a session, PHP will begin watching the variables you register with session_register.

boolean session_unregister(string name)
Use session_unregister to remove a global variable from the session. It will not be saved with the session when the script ends.


All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

PHP Topics