Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

storing arrays in sessions

  • 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, Registered Users 2 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