RE: Problem with sessions!
| From: | Nold, Mark | Date: | Thu, 26 Oct 2000 07:34:01 +0000 |
| Subject: | RE: Problem with sessions! | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-3502@lists.php.net to get a copy of this message | ||
----------------------------------------------------------------------------
-----------------
Disclaimer: The information contained in this email is intended only for the
use of the person(s) to whom it is addressed and may be confidential or
contain legally privileged information. If you are not the intended
recipient you are hereby notified that any perusal, use, distribution,
copying or disclosure is strictly prohibited. If you have received this
email in error please immediately advise us by return email at
postmaster@normandy.com.au and delete the email document without making a
copy.
----------------------------------------------------------------------------
-----------------
Why destroy the session?
Why not just unset the variables?
unset($GLOBALS["first_name"]);
unset($GLOBALS["last_name"]);
unset($GLOBALS["score"]);
unset($GLOBALS["question"]);
Then you could simply call this everytime some one wants to start a new
test. Makes much more sense as you can then have the same user do different
tests with reentering their name (you can default the info)
A session is simply a key to your session variables. Its the session
variables (which are all globals from memory).
What i typically do is set an array as the session variable allowing me to
dynamically allocate and easily find my session values.
so something like the following (i dont have the manual or a system in front
of me but you should get the idea)
register_variable("SESSION");
.
.
.
.
$SESSION["name"] = "Mark Nold";
$SESSION["score"] = 12475.25;
$SESSION["email"] = "markn@alverstone.com.au";
$SESSION["theme"] = "More fruit for mew";
Now i know everything is in $SESSION and i dont have to worry about adding
100's of variables with register_variable() i can also easily find all my
session vars by
while(list($key,$value) = each($SESSION)){
echo "</b>$key</b> $value<br>\n";
}
If you have multiple deveopers working on a project i recomend you set up
several of these session arrays and put them in a prepend. We have a SESSION
one for info for that session, USER for info about the user who logged in,
and application stuff held in APPLICATION, we also have a PUBLIC for
anything not critical. Then within these we have defined keys fopr the
arrays so everybody is working together and no body trashes the wrong data.
Hope this helps. (PS: There may be better ways but this works well)
mn
-----Original Message-----
From: Mikael Lundgren [mailto:diverge@crosswinds.net]
Sent: Tuesday, October 24, 2000 8:25 PM
To: php-windows@lists.php.net
Subject: Problem with sessions!
I'm having a annoying problem with sessions.
I've been making a knowledge test basically using two files.
file1.php that gets username, starts session, gets number of files from a
database etc.
file2.php that show the questions from the database and then returns the
answer to file1.php using a ordinary A HREF.
Everything works fine until it's supposed to close the session (with
session_destroy();) the session gets destroy (i don't get a error message
anyway) and
all the outputs are fine. But if i start the program again from the same
browser instance it returns the old data (like username).
So the only thing i know to destroy the session is to close the browser!
I start the session with
session_start();
and then i register a bunch of variables the first time the page is
accessed..
and when all output is done i do
session_unset();
session_destroy();
exit;
And close the window (but there's another window behind it)
Please help.. i've tried basically everything but i can't seem to solve
it!!!