Start and switch between PHP sessions

Start one names session, switch to another session with another name, switch back again.

Init

Starting the testcase with a session like this:

Session name: S1
Session id: ncuhre0ks470jkk5jhfa0op9t1
$_SESSION contains:

Array
(
)

Incrementing a session variable

Session looks like this:

Session name: S1
Session id: ncuhre0ks470jkk5jhfa0op9t1
$_SESSION contains:

Array
(
    [i] => 1
)

Switch to another named session

Session looks like this:

Session name: S2
Session id: mpducb4dde2cm0oktom6c7ous7
$_SESSION contains:

Array
(
    [mumin] => Mumin Object
        (
            [troll] => 
        )

)

Incrementing a session variable

Session looks like this:

Session name: S2
Session id: mpducb4dde2cm0oktom6c7ous7
$_SESSION contains:

Array
(
    [mumin] => Mumin Object
        (
            [troll] => 1
        )

)

Switch back to first session

Session looks like this:

Session name: S1
Session id: ncuhre0ks470jkk5jhfa0op9t1
$_SESSION contains:

Array
(
    [i] => 1
)

Once again?

Reload the page to run again or run it and destroy the current session.

Array
(
)

Conclusion

It is possible to switch between multiple sessions in PHP. Be sure to initiate the second session correctly (when its first used), otherwise it will be a copy of the existing $_SESSION.

HTML5 CSS CSS3 Unicorn i18n Sourcecode