Jump to content

[SOLVED] Does session_start have to be called inside a function?


therealwesfoster

Recommended Posts

session_start() needs to be called before you use a session variable.  Doesn't matter if it's inside or outside of a function.  session variables are already global.  If you assign something to a session variable without (or before) calling session_start(), it will act like a normal global variable for that page, but will not persist to other pages.

Instead of c/p'ing it here and asking if it will work, you could always c/p it to a test.php and run it and find out.

 

1. I didn't copy, I wrote it real quick.

2. I didn't ask if it would work, I just made a statement before marking the topic as solved.

 

Wes

hmm I coulda swore I saw a question mark in there, hence the statement. My bad.  But for argument sake, for #1, I meant it in a more generic sense.  As in, if you're going to take the time to put it in one place, why not just put it in another place, click the proverbial run button and see what happens?

hmm I coulda swore I saw a question mark in there, hence the statement. My bad.  But for argument sake, for #1, I meant it in a more generic sense.  As in, if you're going to take the time to put it in one place, why not just put it in another place, click the proverbial run button and see what happens?

 

10-4. I wasn't offended ;)

 

Wes

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.