By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

session.auto_start and session arrays?

TheServant
Expert 100+
P: 1,168
Is there any problem with using session.auto_start in the php.ini instead of declaring session_start() on every page?

Also, can sessions store arrays, and if so, is this a good idea?
Feb 11 '08 #1
Share this Question
Share on Google+
5 Replies


ronverdonk
Expert 2.5K+
P: 4,258
As for autostart, better read the following warning from the PHP mmanual:
If you do turn on session.auto_start then you cannot put objects into your sessions since the class definition has to be loaded before starting the session in order to recreate the objects in your session.
PHP manual session.auto_start

If you mean if the $_SESSION array can hold arrays: yes. And it is an easy way of transferring data between pages.
Storing arrays in 'flat' variables is somewhat more elaborate, because you have to serialize/unserialize them.

Ronald
Feb 11 '08 #2

TheServant
Expert 100+
P: 1,168
So with session arrays: I tried it, but I have realised to use it I will need to write something like:
[PHP]
$array = array($_SESSION['array_name']);
$array['variable_a'];
[/PHP]

Is it better to have that done on the page I need to unpack that array and leave only arrays as session variables, or just have 100 session variables which are more easily accessible? Is one quicker that the other?
Feb 11 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
You should take into account that serializing/unserializing can take up a lot of memory storage.
If you want to just pass an array from one form to another via submit, you can serialize it into a hidden form field.
But I would still prefer to use flat variables in the $_SESSION array, even 100, in a case where I'd have a lot of pages that will address those variables.

Ronald
Feb 11 '08 #4

TheServant
Expert 100+
P: 1,168
Sounds good, that's the way I have it set up at the moment. No other opinions?
Feb 12 '08 #5

TheServant
Expert 100+
P: 1,168
Thanks heaps ronverdonk, this can be closed.
Feb 13 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.