Multiple sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
appu
Forum Newbie
Posts: 1
Joined: Wed Nov 10, 2004 3:02 am

Multiple sessions

Post by appu »

Hai Friends,

I need to maintain more sessions in the project.
Is there any possibility to maintain more than one session in the project.
Please give me an advice.

Thank you friends,
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

What is the reason for multiple sessions..

if it is hold multiple variables in the session with the same name you could do this:
since the session variable is an array $_SESSION['key']=$value; you could do $_SESSION['session_one']['varialbe']=something and $_SESSION['session_two']['var']=somethingelse; .... read up on working with multi-demensional arrays


Code: Select all

<?php

session_start();
?><pre><?
$_SESSION['test']['hi']="bye";
print_r ($_SESSION);
?></pre>

this should output:

Code: Select all

Array
(
    &#1111;test] =&gt; Array
        (
            &#1111;hi] =&gt; bye
        )

)
You can alter the code an add on to it and do this:

Code: Select all

Array
(
    &#1111;session1] =&gt; Array
        (
            &#1111;username] =&gt; blah
        )
    &#1111;session2] =&gt; Array
        (
            &#1111;username] =&gt; blah
        )

)
Post Reply