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
mike08
Forum Commoner
Posts: 57
Joined: Mon Apr 19, 2004 3:18 am

sessions

Post by mike08 »

im a bit confused with sessions though

should i put start_session(); on every page including my index.php page which is my homepage.

i have these files before a user logs in

forgot password
register
home

when a user logs in they have access to

poll
change password
guestbook

do i have to put include session_start; on every page its just ive included it on guestbook and it comes up with this error

A session had already been started - ignoring session_start() and the same message on the change password page.

im not using sessions on the guest book page or the change password page is that why? Its just i though you had to include start_session() on every page you view once logged in? is this correct or am i doing something wrong

please can someone advise me what to do and which pages should include sessions?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You only need to use session_start on pages when you need access to session variable.

for example, you could start a session, then go to another page that doesn't need the session variable, then on another page, restart the session and have access to the session variable from the first page.

As for the error message, are you including any files that you may have put session_start in?

Mark
mike08
Forum Commoner
Posts: 57
Joined: Mon Apr 19, 2004 3:18 am

Post by mike08 »

Thanks i think i understand now

it seems to work fine now

ive taken out the start_session in guestbook and change password as im not using session variables on those pages.

cheers.

quick question.

on my site a registers then gets sent to the homepage where then can leave comments in the guest book. i obviously don't want to have them fill in another username and and email address as will already have that.

so in the form would i just call up their information using session variables, could you give me a little examle as to how to do that please?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

read this tutorial.

Not exactly what you need, but if you read it, you will understand more and be able to figure it out for yourself - viewtopic.php?t=6521

Mark
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Didn't I already tell you how to do that or was that someone else? well it was a recent thread anyways - this forum has a serch function!
Post Reply