00 Votes

PHP: Can I set Session Variables within Functions?

Question by Guest | 2014-06-30 at 11:02

In one of my PHP scripts, I would like to work with session variables ($_SESSION), also within functions.

Before starting to program this script, I would like to know, whether this is possible at all or if there are any objections for not doing so? So, can I normally work with session variables within functions or can this lead to any problems?

Such as setting a value within a function and having no access to this outside the function or vice versa or any other problems, for example.

ReplyPositiveNegative
0Best Answer0 Votes

$_SESSION is global and can be used everywhere, also within functions.

You only have to take care off always calling session_start() before setting or accessing any $_SESSION variable, otherwise it is not working.
2014-06-30 at 11:02

ReplyPositive Negative
Reply

Related Topics

PHP: Upload of large Files

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.