- Messages
- 562
- Reaction score
- 1
- Points
- 18
[Closed] session variables and functions (PHP)
Hi.
My main_file.php calls functions.php. I'd like to declare a session variable in functions.php (in one particular function, that is) and use it in main_file.php. I can't return it since I'm already returning another function (so why the hell did they think we would always need to return only one variable anyway??).
My first attempt gave an error like "Unexpected '[' on line whatever" when I tried to make it global. Fine, how am I suppose to declare a session variable if I don't use a '['? I also tried without making it a global variable (since a session variable should be pretty much global anyway), as well as with and without a session_start() in my functions.php. The best result I got was my page echoing "f" when asked for $_SESSION[my_variable], which I assume means false.
So my second attempt was to bypass that, make a global $my_variable and set it as $my_variable = $_SESSION[my_variable]. I'm explaining it in short of course, it's not my actual code. The result was, well, that it was simply ignored by my main_file.php. In my face I guess.
So, put very short and simple, how am I supposed to create a session variable inside my function?
Hi.
My main_file.php calls functions.php. I'd like to declare a session variable in functions.php (in one particular function, that is) and use it in main_file.php. I can't return it since I'm already returning another function (so why the hell did they think we would always need to return only one variable anyway??).
My first attempt gave an error like "Unexpected '[' on line whatever" when I tried to make it global. Fine, how am I suppose to declare a session variable if I don't use a '['? I also tried without making it a global variable (since a session variable should be pretty much global anyway), as well as with and without a session_start() in my functions.php. The best result I got was my page echoing "f" when asked for $_SESSION[my_variable], which I assume means false.
So my second attempt was to bypass that, make a global $my_variable and set it as $my_variable = $_SESSION[my_variable]. I'm explaining it in short of course, it's not my actual code. The result was, well, that it was simply ignored by my main_file.php. In my face I guess.
So, put very short and simple, how am I supposed to create a session variable inside my function?
Last edited: