The World of Sessions.

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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

The World of Sessions.

Post 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.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

don't close the session on the current page.
Just use session_open() at the top of the next.
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post 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.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Thanks everyone I've now got sessions working how I need them to.

Woohoo! :D
Post Reply