Beginner PHP Tutorial – 74 – Unsetting PHP Sessions

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

33 responses to “Beginner PHP Tutorial – 74 – Unsetting PHP Sessions”

  1. Michael Taylor Avatar

    Pro-tip: always make sure you text editor has its ENCODING set as UTF-8. Other types, like ANSI places in hidden characters and can mess with your session_start();

  2. Romzik Keep Calm and Carry On Avatar

    What's up!
    I'd rather use two construction to destroy sessions!
    First:
    $_SESSION = []; – It's deleted array of session
    Second:
    sesstion_destroy(); – remove data from the server(where it's stored in temprorary files)

  3. H T R Avatar

    the problem you were showing, i had the same problem but the other example. so seeing this example was like i know the problem that Alex talking about

  4. Mohamed Arkib Avatar

    what if i restart the browser, will the session be still there?

  5. Guram Kankava Avatar

    Thank you very much. very useful.

  6. Keus Vapor Avatar

    NOTE to beginners: WE DONT SAY UNSET SESSIONS, WE SAY UNSET SESSION VARIABLES.
    session_start(): will check if a session was already started, if not, it will start a session between client and server. We cant create multiple sessions.
    unset($_SESSION['variable']) and session_unset() will only affect the session variables, the session will stay alive. u can add other session variables later.
    Session is destroyed only if session_destroy() is invoked, or due to session expiration/timeout

  7. Vishal Rahate Avatar

    what is the session expiration time?

  8. granim32 Avatar

    Love your vids!, you sound like Danielle Radcliffe btw or he sound like you 🙂

  9. V. Peters Avatar

    great vid. clear.

  10. Adam Romanowski Avatar

    Thanks man! That was useful!

  11. Shady Avatar

    thx man !! i was realy need to understand that

  12. Robert Balejik Avatar

    when you've different session you'd probably use:  unset($_SESSION[$username]);
    so you'd end session for particular user cause each user has obviously diff username

  13. mmafan400 Avatar

    +Cj Vaans , Not better, different. session_destroy() will unset ALL of the sessions on your server, where unset will allow you to be specific. For example, let's say you are using sessions to log in users to your website. You want all of them to be able to login at the same time, as well as log out when they want. If you used session_destroy(), when one person logs out, it would log out ALL users. So instead, you use unset to specifically logout one user

  14. Cj Vaans Avatar

    Would using session_destroy() be better instead of using unset?

  15. Marcos Pereira Avatar

    "Welcome, . You are !" – Yoda

  16. pinoch12000 Avatar

    if you get a NOTICE error be sure to set the error reporting in you php.ini to error_reporting=E_ALL & ~E_NOTICE and reset Apache.

  17. Sheng Long Avatar

    just go on php.net and type in session_destroy or unset or session_start or $_SESSION for descriptions and decent examples of what they all do !

  18. Asith Mahat Avatar

    No mate.. i did.. Alex clearly mentioned you need session_start(); before you end/destroy one/more!!

  19. Rijin Mk Avatar

    Bet you didnt session_start();

  20. Yuriy Soltys Avatar

    why he still don't mention classes? Maybe would be smarter first explain language and then build-in library?

  21. Mithun Sudheendran Avatar

    after unsetting the session…
    press the submit button of set.php file without filling the form.. and see that it still showing "welcome alex"
    please help

  22. Asith Mahat Avatar

    session_destroy();
    didnt work out 4 me…

  23. abhishek sehgal Avatar

    i am setting 2 session namely username and age in the set file and then view the view file it works fine but when i am unset the one session in the unset file and then viewing the view file there comes the problem ie:
    error:
    Notice: Undefined index: username in C:xampphtdocsthenewbostonview_session.php on line 5

    so the error appears if we unset the session or not

  24. jambla Avatar

    @robertjm94706 Alex is setting an age session in the set.php file.

    The code:

    $_SESSION['username']="Alex";
    $_SESSION['age']="21";

    The session_start(); is like a big container that holds multiple values. In this case it's holding the values; username and age.

    In the view.php file he is just simply echoing out the two values IF the session is set, or started.

    I hope this makes sense.

  25. robertjm Avatar

    Am I missing something? Where are you declaring your age is 21? I don't see an age.php in your session folder.

  26. PancakePlease Avatar

    @thesickbeat but wouldn't storing it into a variable in a reference page (forgot what they call it. a config page or something) save time so you don't always have to type out $_SESSION['name']; everytime? I guess it would save time only if it's used very redundantly.

  27. minutesTOmidnigh7 Avatar

    whyyy i have an error undefined variableeeeee :@:@:@:@:@::@ at unset

  28. Ejaz Karim Avatar

    @thesickbeat Thanks…

  29. Ph0.3niX Avatar

    You should also do a tutorial on session arrays. 🙂

  30. Ejaz Karim Avatar

    very nice alex. thanks a lot ,
    so i have a question
    can i use this
    $_SESSION['name']='myname';
    $alex = $_SESSION['name'];
    echo $alex;

  31. supergunboy007 Avatar

    What's that ghost-breathing sound? O_O

Leave a Reply

Your email address will not be published. Required fields are marked *