PHP Learning Note: Delete and destroy session

Source: Internet
Author: User

Deleting a session value can use PHP's unset function, which is removed from the global variable $_session and cannot be accessed.

Session_Start (); $_session[' name '] = ' jobs '; unset ($_session[' name '); Echo $_session[' name ']; Hint name does not exist

If you want to delete all sessions, you can use the Session_destroy function to destroy the current Session,session_destroy delete all data, but session_id still exists.

Session_Start (); $_session[' name '] = ' jobs '; $_session[' time ' = time (); Session_destroy ();

It is important to note that Session_destroy does not immediately destroy the value in the global variable $_session, but only when the next time it is accessed, $_session is empty, so if you need to destroy $_session immediately, you can use the unset function.

Session_Start (); $_session[' name '] = ' jobs '; $_session[' time ' = time (); unset ($_session); Session_destroy (); Var_dump ($_session); This is now empty

If it is necessary to destroy the session_id in the cookie at the same time, usually when the user exits, it is also necessary to explicitly call the Setcookie method to remove the session_id cookie value.

Task

Use unset to remove the session value for name.

<? PHP Session_Start (); $_session [' name '] = ' jobs '; // Delete the session value of name here unset ($_session[' name ']); if (isset($_session[' name ')]) {    echo$_session[' name '] ];     return ;}   Echo ' Session is destroyed ';

PHP Learning Note: Delete and destroy 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.