Summary of the session deletion and emptying method in PHP

Source: Internet
Author: User


1. unset ($_session[' xxx ') deletes a single session,unset ($_session[' xxx ')) to unregister a registered session variable. The effect is the same as Session_unregister ().


Session_unregister () has been discarded in the PHP5.

<?php          //  initialization session.

         session_start ();          /***  Delete all Session variables ... Unset ($_session[xxx]) can also be deleted individually.

/         $_session = array ();          /*** Delete sessin  ID. Because the session defaults to cookies, use Setcookie to remove the cookie.***/that contains Session id           if  (Isset ($_cookie[session_name ()))  {                setcookie (Session_name (),  ',  time () -42000,  '/'

);           }         

 //  finally completely destroy the session.

         session_destroy (); ?>

Unset ($_session) This function must not be used, it will destroy the global variable $_session, and there is no feasible way to restore it. Users can no longer register $_session variables.

2, Session_unset () or $_session=array () delete multiple sessions

3, Session_destroy () ends the current session and empties all resources from the session. The function does not unset (release) the global variable (globalvariables) associated with the current session, nor does it delete the client's session cookie. PHP default session is based on cookies, and if you want to delete cookies, you must use the Setcookie () function.

Summarize:

Session_destroy is the cancellation of all the session variables and the end of sessions;

If you want to delete some session data, you can use either the unset () function or the Session_destroy () function. The role of the unset () function is to release the specified session variable, which is called in the following format:

<?php

unset ($_session[' Jugelizi '));

? >


The Session_destroy () function is to delete all sessions and call the following format:

? PHP Session_destroy ();?>

Tip: Session_destroy () will reset the session and you will lose all saved session data.

Session_unset () does not unregister the session variable, but clears the value of all session variables.

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.