We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

$session->start(); clears existing Memcache key

Hi! I use this code generated by Phalcon Developer Tools

use Phalcon\Session\Adapter\Memcache as SessionAdapter;

$di->set('session', function () {

    $session = new SessionAdapter(array(
        'host' => '127.0.0.1',
        'port' => 11211,
        'lifetime' => 8600,
        'prefix' => 'memc.sess.',
        'persistent' => false
    ));

    $session->start();

    return $session;
});

I have existing Memcache key and $_COOKIE['PHPSESSID'].

$session->start(); create session with sid = $_COOKIE['PHPSESSID'] but clears all existing data in Memcache key.

How can i fix it?



98.9k

Currently $session->start() does not reset any cookies, what version of Phalcon are you using?

edited Sep '14

No, all right with my cookie. I use 1.3.2

$session->start() get sid from cookie, so in Memcache session data is in 'memc.sess.'.$_COOKIE['PHPSESSID'] key and it's cool.

But this key has already data, for example 'user_id', because I logged in another subdomain, which does not use phalcon.

And $session->start() clear all data in 'memc.sess.'.$_COOKIE['PHPSESSID'] Memcache key.



98.9k
edited Sep '14

I think, you may want to check this function: https://php.net/manual/en/function.session-set-cookie-params.php, this will allow you to set the cookie on every subdomain

session_set_cookie_params(0, '/', '.some_domain.com');
edited Sep '14

I'm sorry, you did not understand me. My cookie is allowed.

I logged in another subdomain and save my session into Memcache with key

'memc.sess.key.'.$_COOKIE['PHPSESSID']

Then I go to the subdomain with phalcon. Phalcon "see" my cookie with sid and it runs session with the same sid. It's fine for me.

But...

Before $session->start()

$mc->get('memc.sess.key.'.$_COOKIE['PHPSESSID'])

return

user_id|s:5:"xxxxx";user_login|s:10:"xxxxx";user_name|s:12:"xxxxxx";user_level|s:5:"xxxxx";user_sex|s:4:"male";user_ip|s:14:"xxx.xxx.xxx.xxx"

but after $session->start() it's return empty string, because $session->start() remove all data in my Memcache key.

This is my problem...