SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Session question

    How do you add multiple data to a single session? I tried an array but I think im doing it wrong:

    $_SESSION['test'] = $testing;

    $testing[0] = 'Whatever';
    $testing[1] = 'Something';

    echo $_SESSION['test'][1];

    This doesnt work.

    Thank you
    Silly

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry I can't help, though for anyone who can help, I'd be interested to know as well

  3. #3
    SitePoint Wizard Sillysoft's Avatar
    Join Date
    May 2002
    Location
    United States :)
    Posts
    1,691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I got it to work this way:

    <?php
    session_start();
    $testing[] = 'Hi';
    $testing[] = 'Hiagain';
    $_SESSION['test'] = $testing;
    echo
    $_SESSION['test'][1];
    ?>

    But that means I have to pre-determine the array. It is for a shopping cart.. Sorta. All I want to do is have a user browse products, click on add to cart. Check to see if the session is already there, if not then create a new session, if so then just add it to the session array. I could be doing this all wrong though

    Silly

  4. #4
    SitePoint Evangelist compwizard's Avatar
    Join Date
    May 2002
    Location
    United States
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could just use this:
    PHP Code:
    $_SESSION['userid'] = 12345;
    $_SESSION['username'] = "compwizard"
    Compwizard
    "There are 10 kinds of people in this world -- those who know binary, and those who don't."

  5. #5
    No. Phil.Roberts's Avatar
    Join Date
    May 2001
    Location
    Nottingham, UK
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $session['data_array'] = serialize(array('one', 'two'));


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •