[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Beginner PHP Tutorial – 74 – Unsetting PHP Sessions
by
Tags:
Comments
33 responses to “Beginner PHP Tutorial – 74 – Unsetting PHP Sessions”
-
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();
-
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) -
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
-
what if i restart the browser, will the session be still there?
-
Thank you very much. very useful.
-
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 -
what is the session expiration time?
-
great job sir !!!
-
Love your vids!, you sound like Danielle Radcliffe btw or he sound like you 🙂
-
great vid. clear.
-
Thanks man! That was useful!
-
thx man !! i was realy need to understand that
-
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 -
+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
-
Would using session_destroy() be better instead of using unset?
-
"Welcome, . You are !" – Yoda
-
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.
-
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 !
-
Is he 21!?
-
No mate.. i did.. Alex clearly mentioned you need session_start(); before you end/destroy one/more!!
-
Bet you didnt session_start();
-
why he still don't mention classes? Maybe would be smarter first explain language and then build-in library?
-
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 -
session_destroy();
didnt work out 4 me… -
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 5so the error appears if we unset the session or not
-
@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.
-
Am I missing something? Where are you declaring your age is 21? I don't see an age.php in your session folder.
-
@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.
-
whyyy i have an error undefined variableeeeee :@:@:@:@:@::@ at unset
-
@thesickbeat Thanks…
-
You should also do a tutorial on session arrays. 🙂
-
very nice alex. thanks a lot ,
so i have a question
can i use this
$_SESSION['name']='myname';
$alex = $_SESSION['name'];
echo $alex; -
What's that ghost-breathing sound? O_O
Leave a Reply