Page 1 of 1
Save session
Posted: Thu Mar 03, 2005 10:58 am
by laurielle
Hello all,
I'm new in this forum and I hope you can help me.
I have to save my session when I close the brower. So i use the cookie to save the session_id, but how can I find the variables which I stored in $_SESSION before closing browser.
Thanks in advance.
Regards.
Laurielle
Posted: Thu Mar 03, 2005 11:11 am
by feyd
care to explain some more?
You can save the session data in a database, this will give you more access to the data across sessions and things.. If that's what you need, there's a thread on how to set up database sessions in the Useful Posts thread.
Posted: Thu Mar 03, 2005 11:14 am
by anjanesh
Say for example for "Always keep me logged on this PC" or "Remember Me"
Code: Select all
if (isset($_POSTї'RememberMe'])) setcookie ("StoreUser",$user,time()+3600*24*365,"","",0);
Then you can access it again if stored in cookie
Code: Select all
if(isset($StoreUser))
// Automatic Login
Posted: Thu Mar 03, 2005 11:17 am
by feyd
anjanesh wrote:Then you can access it again if stored in cookie
Code: Select all
if(isset($StoreUser))
// Automatic Login
... this code works,
provided register_globals is on..
which they should not
Posted: Thu Mar 03, 2005 11:34 am
by anjanesh
But theres no getcookie()
Posted: Thu Mar 03, 2005 11:37 am
by Chris Corbyn
anjanesh wrote:But theres no getcookie()
huh

Where did that come from ?
feyd meant the way the variable is called.

$_COOKIES[]

Posted: Thu Mar 03, 2005 11:49 am
by laurielle
To explain my problem, i give you an example.
I'm logged, I answer questions for exam, and for make a break during exam, I have to close the browser directly. When I open again my browser and I logged , I have to find the last question before closing browser. So I have to find the last informations which I have stored in $_SESSION. In my database, I save the data when I valid my answer, so it's not sufficient. I need variables in $_SESSION.
I hope it's more clear.
And another pb with this: the exam has to last 90min so I have to manage the time when I make a break.
Regards.
Laurielle
Posted: Thu Mar 03, 2005 11:51 am
by Chris Corbyn
feyd wrote:You can save the session data in a database, this will give you more access to the data across sessions and things.. If that's what you need, there's a thread on how to set up database sessions in the Useful Posts thread.
This is the best and most foolproof way. Keep it on the server...
Read up on this as feyd initially suggested

Posted: Thu Mar 03, 2005 3:25 pm
by laurielle
I read the code in the Useful Thread and the example in the website php.net about session_set_save_handler(), but I don't understand many things.
Can you explain me please what I have to code in these functions ? (read, write, open, gc) it's not clear at all.
Do I have to create a db for do that?
Thanks in advance.
Posted: Thu Mar 03, 2005 3:40 pm
by John Cartwright
have you looked them up in the manual?
php.net/functionnamehere
Posted: Thu Mar 03, 2005 3:44 pm
by laurielle
Yes,
http://ca.php.net/manual/fr/function.se ... andler.php
I would like to do like in the example of the site (storage in file), but when I call these functions, what i have to write for $sess_save_path and others variables ?
Posted: Thu Mar 03, 2005 3:47 pm
by smpdawg
First visit
1. Keep the session information in the database.
2. Use the session as a caching mechanism for when the user is on the site.
3. Store some identifier in a cookie to help the site identify the user.
When they revisit the site.
4. Get the cookie.
5. Find their information in the database and repopulate the session.
Posted: Thu Mar 03, 2005 4:45 pm
by laurielle
Can I keep the session information in a file? What is the way?