SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    Republic of Ireland
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retrieving Server-side Session Data

    Like it says on the packet, is it possible to retrieve an array of data from a server-side $_SESSION?
    Code:
    sess_cb558c02d13e45c59c0c13411a4e5dc8 contains confirm|a:1:{s:7:"display";s:7:"desktop";}
    sess_11cb42acaa443b1660a0a2d97976900c contains confirm|a:2:{s:7:"display";s:7:"desktop";s:5:"email";N;}
    sess_bde69c5208e117a5e2e3dde0ef0b6df7 contains confirm|a:2:{s:7:"display";s:7:"desktop";s:5:"email";s:4:"sent";}
    Boy, would I like to get my code around the third one.

    Am I chasing my tail here?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    $_SESSION is already an array.
    PHP Code:
    session_start();

    var_dump$_SESSION ); 
    If you are trying to be "clever" and do things the long way around by toying with the raw files: http://php.net/manual/en/function.serialize.php
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    Republic of Ireland
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    $_SESSION is already an array.
    PHP Code:
    session_start();

    var_dump$_SESSION ); 
    Thanks for that. I didn't think to dump the array. I'm just trying to keep track of two 'states' in the event that a browser is refusing cookies. The array corresponding to that third session is interesting:
    Code:
    array(1) {   ["display"]=>   NULL } array(2) {   ["display"]=>   string(7) "desktop"   ["email"]=>   NULL }
    Yet the session cookie array is:
    Code:
    confirm|a:2:{s:7:"display";s:7:"desktop";s:5:"email";s:4:"sent";}
    So I guess my code is not asking the right questions here.

    I actually use serialize() and unserialize() to store the arrays in proper honest-to-goodness cookies for browsers that accept them. I didn't realise I could do that with $_SESSION.

    NOTE: My apologies, that array of results is all wrong. In fact the session is being stored. I'm just not retrieving it in the code. Thanks again for the debugging advice.
    Last edited by Enver; May 2, 2013 at 13:13. Reason: Learning fast


Tags for this Thread

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
  •