Home  >  Article  >  Backend Development  >  Add, delete, modify and view operations of PHP SESSION, phpsession_PHP tutorial

Add, delete, modify and view operations of PHP SESSION, phpsession_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:01:55841browse

Add, delete, modify and view operations of PHP SESSION, phpsession

The difference between SESSION and COOKIE is that first of all, the cookie file is saved on the client, while the session is Compared with those stored on the server, in order to improve a certain level of security, session has more advantages.

Because the session is generally managed by the server administrator on the server side, but the cookie is saved on the client side and can be viewed by anyone. If it is not specified, the password is also saved in clear text, so the security is obvious.

And session is relatively more powerful and can save arrays and even objects. To some extent, it can reduce development costs.

The following is the session usage code:

Increase of session data:
Copy code The code is as follows:
Header("Content-type: text/html; charset=utf-8;");//Displayed in utf-8, has nothing to do with session
Session_start();//Start saving session data
$_SESSION['name']="xuning";*//Add session data.
?>

Deletion of session data.
Copy code The code is as follows:
Header("Content-type: text/html; charset=utf-8;");//Displayed in utf-8, has nothing to do with session
Session_start();//Start session data
Unset($_SESSION['name']="xuning");*//Delete session data.
Session_destory();//Delete all sessions
?>

The modification of session is the addition of session data.
Viewing session data means taking out session data.

Copy code The code is as follows:
session_start();
print_r($_SESSION);//Get session
echo $_SESSION['name'];
?>

Both cookies and sessions end with a session, that is, closing the browser ends a session.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/970994.htmlTechArticleAdd, delete, modify, view operations of PHP SESSION, the difference between phpsession SESSION and COOKIE is first of all, cookie The file is saved on the client, and the session is saved on the server...
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