WordPress.org

Ready to get started?Download WordPress

Forums

Simple Session Support
[resolved] simpleSessionSet($key, array()); (4 posts)

  1. Cristiano
    Member
    Posted 10 months ago #

    Hi friends,

    What should I do to work with array() for session $value?

    My session should be: $_SESSION['hashed_urls'][$_url]=$value;
    How to set it using Simple Session Support plugin?

    Thanks!
    Cristiano

    http://wordpress.org/plugins/simple-session-support/

  2. Jules Colle
    Member
    Posted 9 months ago #

    I needed the same thing (looks like I'm the most active user of this plugin.. :))

    I modified the Get and Set functions like so:

    function simpleSessionGet($key, $default='') {
        if(isset($_SESSION[$key])) {
            return unserialize($_SESSION[$key]);
        } else {
            return $default;
        }
    }
    function simpleSessionSet($key, $value) {
        $_SESSION[$key] = serialize($value);
    }

    The trick is to save all data serialized in the session, and unserialize it again when you need to retrieve it.

    If you don't like to modify the plugin code (even though I believe the code is more robust with my modifications), you could just call the functions like this: simpleSessionSet($key, serialize($value)) and unserialize(simpleSessionGet($key))

    In you particular case
    $_SESSION['hashed_urls'][$_url]=$value;
    would be equivalent to
    simpleSessionSet('hashed_urls', array($_url=>$value));
    if you used the modified plugin code.

  3. Peter Wooster
    Member
    Plugin Author

    Posted 9 months ago #

    Thanks Jules,

    Serialization is the way to go, I'll probably add it as an option in the next release. I just completed testing everything for WP 3.8, but I will be making updates to my plugins.

    /peter

  4. ianarmstrong
    Member
    Posted 7 months ago #

    This is such an easy change to make, I'm not sure why you haven't just pushed it.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags