PHP session to add, delete, modify, view operations _php skills

Source: Internet
Author: User
Tags php session

The difference between a session and a cookie is that the file of the cookie is stored on the client, and the session is saved in the server, in order to improve security, the session has advantages.

Because the session on the server side of the general situation is the management of the server, but cookies are saved in the client, anyone can see, if not specified, password is also clear, security is obvious.

And the session is relatively more powerful, you can save the array, and even objects, in a way, can reduce the development costs.

Here is the use code for the session:

Increase in session data:

Copy Code code as follows:

<?php
Header ("content-type:text/html; Charset=utf-8; "); /UTF-8 Display, not session-independent
Session_Start ()//Start session data Save
$_session[' name ']= ' xuning '; *//add session data.
?>

deletion of session data.
Copy Code code as follows:

<?php
Header ("content-type:text/html; Charset=utf-8; "); /UTF-8 Display, not session-independent
Session_Start ()//Start session data
unset ($_session[' name ']= "xuning"); *//Delete session data.
Session_destory ()//Delete all sessions
?>

Session modification is the increase in session data.
The session data is viewed, that is, the session data is removed.

Copy Code code as follows:

<?php
Session_Start ();
Print_r ($_session);//Get session
echo $_session[' name '];
?>

Whether a cookie or session ends with a conversation, closing the browser closes a session.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.