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!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi all,
I’m working on my first project with sessions, kind of getting stuck on what is probably a simple point. Would you mind correcting me? My understanding is that I can declare the session variables in an include file such as
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
You have to call session_start() before using anything with $_SESSION. The problem you are having is you are including your admin.inc file before calling session_start().
guess the only thing leaving me a little puzzled is why do ALL the tutorials I've been working on put the include files at the top seemingly without getting into trouble? I thought I needed to put a reference to the file where I have the session variables before I try use them?
Yes, you need to include the file before you try to access the session variables, but you need to call session_start() before you do anything with sessions at all.
When you include a file, think of it as copying all the code out of the file and pasting it into where the include is.