Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

storing arrays in sessions

Options
  • 12-05-2003 10:51am
    #1
    Closed Accounts Posts: 59 ✭✭


    hi all,
    Does anyone one know how to store an array in a session in php!!

    This is a piece of my code that isn't working:
    if( ! session_is_registered("sQueue") )
    {
    session_register ("sQueue");
    $sQueue = array("Blah");
    }
    else{
    array_push ($sQueue, $title);
    }

    This would work if the variable wasn't an array but I keep getting this error:
    Warning: array_push() [function.array-push]: First argument should be an array

    if ya have any ideas please post em ! I really need help here!
    Thanks


Comments

  • Closed Accounts Posts: 1,325 ✭✭✭b3t4


    $sQueue = array("Blah");
    session_register ("sQueue");

    Declare sQueue as an array first before you
    register it. That should mean that it gets
    registered as an array as aposed to a variable.

    Rgds,
    A.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    My PHP is hugely lacking but shouldn't you declare the array before the conditional. It seems to me that sQueue is only declared as an array if it isn't registered, but I could be wrong.

    [PHP]
    $sQueue = array("Blah");
    if( ! session_is_registered("sQueue") )
    {
    session_register ("sQueue");
    }
    else
    {
    array_push ($sQueue, $title);
    }
    [/PHP]


  • Closed Accounts Posts: 59 ✭✭Fi_C**


    The reason i declare it within the conditional is :
    would it not already be declared as an array and saved as one in the session if it had already been registered?
    I don't want to re initialise it as
    $sQueue = array("Blah");
    everytime I open this page I only want to reinitialise it if it has been unregistered or destroyed!

    :(


Advertisement