How can I clear my php session data correctly?

后端 未结 3 781
离开以前
离开以前 2020-12-11 16:44

My php website flows like this:

  • Page1.php has an html form which POSTs to Page2.php
  • Page2.php stores all the POST data into SESSION variables and has
3条回答
  •  悲哀的现实
    2020-12-11 17:06

    Only use session_unset() for older deprecated code that does not use $_SESSION.

    see session_destroy manual

    example you can try and see how it works

    session.php

    1,'session2'=>2);
    
    echo $_SESSION['session1']; //1
    $_SESSION['session1'] = 3;
    echo "
    ";
    print_r($_SESSION); //session one now updated to 3
    echo "
    "; $_SESSION = array(); if ($_SESSION['session1']) { echo $_SESSION['session1']; // IS NOW EMPTY } else { echo "woops... nothing found"; } ?>

    NOW GOING TO DESTROYED PHP

    destroyed.php

    
    

提交回复
热议问题