Save session

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
laurielle
Forum Newbie
Posts: 8
Joined: Thu Mar 03, 2005 10:55 am
Location: Canada, Montreal, QC

Save session

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

But theres no getcookie()
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

anjanesh wrote:But theres no getcookie()
huh :?: :?: Where did that come from ?

feyd meant the way the variable is called.

:arrow: $_COOKIES[] :idea:
laurielle
Forum Newbie
Posts: 8
Joined: Thu Mar 03, 2005 10:55 am
Location: Canada, Montreal, QC

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :wink:
laurielle
Forum Newbie
Posts: 8
Joined: Thu Mar 03, 2005 10:55 am
Location: Canada, Montreal, QC

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

have you looked them up in the manual?

php.net/functionnamehere
laurielle
Forum Newbie
Posts: 8
Joined: Thu Mar 03, 2005 10:55 am
Location: Canada, Montreal, QC

Post 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 ?
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post 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.
laurielle
Forum Newbie
Posts: 8
Joined: Thu Mar 03, 2005 10:55 am
Location: Canada, Montreal, QC

Post by laurielle »

Can I keep the session information in a file? What is the way?
Post Reply