Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Session DB driver problem
  • Hello,
    I was wondering if anyone knows how to fix the error:

    [22-Jan-2018 05:26:14 UTC] PHP Fatal error:  Uncaught Fuel\Core\Database_Exception: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xF1a;FBI...' for column 'user_agent' at row 1 with query: "INSERT INTO session (session_id, previous_id, ip_hash, user_agent, created, updated, payload) VALUES ('[cutout]', '[cutout]', '[cutout]', 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13B143 [FBAN/FBIOS;FBAV/;FBBV/34183777;FBRV/0;FBDV/iPhone6,2;FBMD/iPhone;FBSN/iPhone OS;FBSV/9.1;FBSS/2;FBCR/OrangeEspańa;FBID/phone;FBLC/es_ES;FBOP/5]', 1516598774, 1516598774, 'a:3:{i:0;a:7:{s:10:\"session_id\";s:32:\"[cutout]\";s:11:\"previous_id\";s:32:\"[cutout]\";s:7:\"ip_hash\";s:32:\"[cutout]\";s:10:\"user_agent\";s:266:\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13B143 [FBAN/FBIOS;FBAV/60.0.0. in /var/www/xxx/platform/fuel/core/classes/session/db.php on line 238

    It seems that Fuel is unable to handle User-Agent strings with characters outside UTF-8 (with the proposed table structure from the documentation), so the session will not work for OrangeEspana mobile users. I think there should be some kind of character mapping to their flat equivalent or stripping the characters that are out of range. What do you think? In my tables I use utf8_mb4, but it seems not enough for this character.

  • That's great, as it is illegal to use non-ASCII characters in the HTTP header, according to the standard.

    You could try changing the column from "text" to "blob"?
  • tested this, seems to work fine.
  • Hello again,
    Seems in general sessions are working this way, but this doesn't fix the original issue.

    I know this is not the problem of the framework as the client uses non-standard characters, so I do not propose changing anything in framework code.

    However, I can write the code by myself to strip the User_Agent from non-standard characters. I was wondering if editing $_SERVER['HTTP_USER_AGENT'] is enough. Can you suggest what place would be good to do not edit the framework base code itself but still do it before framework loads the USER_AGENT into their internals?
  • The session classes use \Input::user_agent(). This in turn calls \Input::server() to read the "HTTP_USER_AGENT" value. That in turn reads $_SERVER.

    So if you want to "pre-treat" $_SERVER, you can do so in your app bootstrap.php, before Fuel::init().
  • Thanks again

Howdy, Stranger!

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

In this Discussion