Page 1 of 1

The World of Sessions.

Posted: Sat Dec 28, 2002 10:36 am
by Gen-ik
I'm thinking about using sessions in a new comminity site I'm putting together. I've always just used MySQL and Cookies before for user accounts and cutomisation etc, which seems to work fine.

I'm currently running through the documents and stuff on Sessions but have a question..

Once someone has logged in and their session variables have all been loaded how the hell do you take this info over to another page on the site?

Do you close the session on the current page and then re-open it on the next?

I know about the <? SID?> thing but when I use this in a link to the next page and try to then close the session I'm told the session isn't open.


Any advise or 'human readable' tutorials would be good.


Thanks.

Posted: Sat Dec 28, 2002 11:49 am
by Bill H
don't close the session on the current page.
Just use session_open() at the top of the next.

Posted: Sat Dec 28, 2002 12:49 pm
by oldtimer
By going

Code: Select all

<?php
session_start();
// whatever else

?>
You will carry over what is in those sessions. To test it just echo out one of the entries in you session. Make sure you put the session_start(); before any other information though.

Posted: Sat Dec 28, 2002 1:32 pm
by Gen-ik
Ah.. so simple. It now works :)


Oh.. just one more small thing.. how do you save the current session and then retrieve the data next time the member logs-on?

I'm a muppet.


Thanks again.

Posted: Sat Dec 28, 2002 2:33 pm
by hob_goblin
Gen-ik wrote:Ah.. so simple. It now works :)


Oh.. just one more small thing.. how do you save the current session and then retrieve the data next time the member logs-on?

I'm a muppet.


Thanks again.
You will have to save this information in a cookie, database, or some other means of storage. Sessions were built for on-the-fly kind of things, not for long term storage.

Posted: Sat Dec 28, 2002 3:39 pm
by Gen-ik
Thanks everyone I've now got sessions working how I need them to.

Woohoo! :D