Skip to content
Advertisement

Setting a session in steps

Is it possible to set multiple session elements to the same session at different times? I have 2 classes and each class should set 2 session elements. What I’m getting back is an empty array. I am using session_start() on each page.

Also, I can set the session successfully from within a single class, but get an empty array back when setting from each class.

JavaScript

EDIT:

Here is the array I would like to create:

JavaScript

Elements 0 and 1 should be set in the user class Elements 2-3 should be set in the part class Elements 4-5 should be set in the serial class

Advertisement

Answer

You can set it but bit different approach need to be used. You can create an array of sessions with different values.

You have to write session_start() on top of each file where you need to use session.

JavaScript

Output looks like:

JavaScript

It’s upto you how do you want to crate this array.

EDIT:

To get your desire format output and add values to array later in different files you can give a try like:

JavaScript

This will give you following output:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement