Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Database session not working
  • Hi, I'm a long time CodeIgniter and Zend Framework user trying out FuelPHP for a simple app. I decided to forgo registration and authentication and use the ip_hash from FuelPHP Session to impose some basic control on user activities. The session config for my app looks like this: 'auto_initialize' => true, 'driver' => 'db', 'match_ip' => true, 'match_ua' => true, 'cookie_domain' => '', 'cookie_path' => '/', 'cookie_http_only' => false, 'expire_on_close' => false, 'expiration_time' => 86400, 'rotation_time' => 300 'db' => array( 'cookie_name' => 'mycookiename', 'database' => null, 'table' => 'sessions', 'gc_probability' => 5 ), [/CODE] I have a controller action which is called by AJAX. It reads Session::key('ip_hash'). However, all it receives is an empty string. When the action is done, no cookie is set in the browser and nothing is written into sessions table in the database. I have tried to print_r the session object I get by calling Session::instance() at the beginning of the action, and it returns empty keys array. Next, I tried this at the beginning of an action: [CODE] $session = Session::instance(); if (!$session->key('session_id')) { $session->rotate()->write(); return 'written'; } [/CODE] The action returns 'written' but still no cookie or a row in database table. What am I doing wrong? My db settings are ok as the rest of the application is working with the db correctly. btw, totally off topic, the forums seem to be falling apart. My name contains non-English characters but they are not being displayed. Formatting buttons are not working, at least in Chorme, reporting "insert_code is not defined ".[CODE]
    'auto_initialize' => true,
    'driver' => 'db',
    'match_ip' => true,
    'match_ua' => true,
    'cookie_domain' => '',
    'cookie_path' => '/',
    'cookie_http_only' => false,
    'expire_on_close' => false,
    'expiration_time' => 86400,
    'rotation_time' => 300 'db' => array(
    'cookie_name' => 'mycookiename',
    'database' => null,
    'table' => 'sessions',
    'gc_probability' => 5
    ),
    [/CODE] I have a controller action which is called by AJAX. It reads Session::key('ip_hash'). However, all it receives is an empty string. When the action is done, no cookie is set in the browser and nothing is written into sessions table in the database. I have tried to print_r the session object I get by calling Session::instance() at the beginning of the action, and it returns empty keys array. Next, I tried this at the beginning of an action:
    $session = Session::instance(); if (!$session->key('session_id')) { $session->rotate()->write(); return 'written'; } [/CODE] The action returns 'written' but still no cookie or a row in database table. What am I doing wrong? My db settings are ok as the rest of the application is working with the db correctly. btw, totally off topic, the forums seem to be falling apart. My name contains non-English characters but they are not being displayed. Formatting buttons are not working, at least in Chorme, reporting "insert_code is not defined ".[CODE]
    $session = Session::instance(); if (!$session->key('session_id')) {
    $session->rotate()->write();
    return 'written';
    }
    [/CODE] The action returns 'written' but still no cookie or a row in database table. What am I doing wrong? My db settings are ok as the rest of the application is working with the db correctly.
    btw, totally off topic, the forums seem to be falling apart. My name contains non-English characters but they are not being displayed. Formatting buttons are not working, at least in Chorme, reporting "insert_code is not defined ".
  • FuelPHP v1.2 as a bug that will cause the session not to be created if it doesn't contain any session variables, which is fixed in 1.2/develop (which will become 1.2.1 in a few days). If you don't want to wait for that you can just pull the session classes from the github repository and overwrite yours. Alternatively, do a Session::set('dummy', 'blah') to force the session to be created. And we are very aware of the issues with this forum. It's running PyroCMS (you know, CI), we're working on a new platform for community interaction, which will include a new forum.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion