Home  >  Article  >  Backend Development  >  php session processing class_PHP tutorial

php session processing class_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:54:56892browse


PHP Tutorial The session variable is used to store information about the user session, or to change the settings of the user session. The information held by the session variable is specific to a single user and is available to all pages in the application.
php session variable
When you run an application, you open it, make changes, and then close it. It's a lot like a session. The computer knows who you are. It knows when you start the application and when it terminates it. But on the Internet, there's a problem: the server doesn't know who you are and what you do, and this is because http addresses cannot maintain state.

PHP session solves this problem by storing user information on the server for subsequent use (such as user name, purchased items, etc.). However, session information is temporary and will be deleted after the user leaves the site. If you need to store information permanently, you can store the data in a database tutorial.

The working mechanism of session is to create a unique id (uid) for each visitor and store variables based on this uid. The uid is stored in a cookie or transmitted through the url.

*/

class my_session
{
function my_session()
{
// destroy sessions started with session.auto_start
if( session_id() )
{
session_unset();
session_destroy();
}

session_start();
}

function set($name, $value)
{
$_session[$name] = $value;
}

function get($name)
{
if(isset($_session[$name]))
Return $_session[$name];
else
Return false;
}

function del($name)
{
unset($_session[$name]);
}

function destroy()
{
$_session = array();
Session_destroy();
}

}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631711.htmlTechArticlephp tutorial The session variable is used to store information about the user session, or to change the settings of the user session. The information held by the session variable is single-user and available to everyone in the application...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn