Error message while logging in in Kohana

☆樱花仙子☆ 提交于 2020-01-14 18:59:08

问题


I'm using Kohana 3 and I have an issue while logging in with an user.

I use this line to log in:

$success = Auth::instance()->login($_POST['login_user'], $_POST['login_password'], $remember);

And I got this error message:

Session_Exception [ 1 ]: Error reading session data. ~ SYSPATH/classes/kohana/session.php [ 326 ]

I have the sessions table created with the follow SQL:

CREATE TABLE `sessions` (
  `session_id` varchar(24) NOT NULL,
  `last_active` int(10) unsigned DEFAULT NULL,
  `contents` text,
  PRIMARY KEY (`session_id`),
  KEY `sessions_fk1` (`last_active`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

And also the session.php inside the config folder:

<?php defined('SYSPATH') or die('No direct script access.');

return array(
    'database' => array(
        /**
         * Database settings for session storage.
         *
         * string   group  configuation group name
         * string   table  session table name
         * integer  gc     number of requests before gc is invoked
         * columns  array  custom column names
         */
        'group'   => 'default',
        'table'   => 'sessions',
        'gc'      => 500,
        'columns' => array(
            /**
             * session_id:  session identifier
             * last_active: timestamp of the last activity
             * contents:    serialized session data
             */
            'session_id'  => 'session_id',
            'last_active' => 'last_active',
            'contents'    => 'contents'
        ),
    ),
);

?>

What might be the problem here?

Thanks!


回答1:


Session_Exception [ 1 ]: Error reading session data. ~ SYSPATH/classes/kohana/session.php [ 326 ]

Depends what version you're running, but this is caused by an exception being thrown when session data is being unserialized in read. You can see the bug report about it here: Session read errors not properly ignored. The solution would be to upgrade to the latest version if you haven't already.

Something else you need to look at is your session data. You'll have to see why your data is corrupt and can't be read properly. This could be an error generated from code in __sleep.




回答2:


I don't know if this will help, but I had a similiar problem.

The cause of this was that using one library (Facebook SDK), session was initialized on it's onw, and session handling was done using the $_SESSION variable. I noticed that there were two cookies - session (Kohanas session id) and PHPSESSID. This probably was the problems cause.

I modified the library so that id doesn't start the session on its own and the problem was solved.

So, you should probalby check if session isn't started elsewhere.




回答3:


Workaround or solution for me was setting php.ini

session.auto_start = 0

Of course, restart your web-server




回答4:


Not sure if you figured this out. But I had the same issue and it was related to my php config. I'm using NGNIX and php-fpm. By default my session files were trying to get saved to a directory that didn't exist. So I changed the session.save_path to a valid path and that fixed it.




回答5:


One way to solve this is to instantiate a session instance before you create a Facebook SDK instance. For example:

$this->_session = Session::instance('native');
$this->_facebook = new Facebook(array(
    'appId'  => 'app_id',
    'secret' => 'app_secret',
));

If you take a look at the code inside the constructor of the Facebook class you'll see it checks if a session has been started:

public function __construct($config) {
    if (!session_id()) {
      session_start();
    }
    parent::__construct($config);
    if (!empty($config['sharedSession'])) {
      $this->initSharedSession();
    }
  }

So if you create the session first it'll skip that block of code.




回答6:


I have had such problems when switching to an online server (more than once :(, so it should be better put some clear guidance).

Recommendations:


§) If you are using Database session adapter:

Session::$default = 'database';   

i.- Check that your DB credentials are correct.
ii.- Check that the table assigned to sessions data has correct type and size.


§) If you are using Encryption for your sessions data (config/session.php or config/.../session.php):

return array(
  'cookie' => array(
    // ...
    'encrypted' => TRUE,
    // ...
    ),
  'database' => array(
    // ...
    'encrypted' => TRUE,
    // ...
    ),
  );

i- Check that you have mcryptinstalled:

$ php -m|grep mcrypt
mcrypt // installed

ii- Check that you are using the same key was used to encrypt data (config/encrypt.php or config/.../encrypt.php):

return array(
    'default' => array(
        'key'    => 'yabadabadoo!',
        'cipher' => MCRYPT_RIJNDAEL_128,
        'mode'   => MCRYPT_MODE_NOFB,
    ),

Workarounds

§) If is possible delete all sessions data and try again.

i) For native adapter: Delete all (or just the corresponding to your app) sessions files located in...

Stores session data in the default location for your web server. The storage location is defined by session.save_path in php.ini or defined by ini_set.

ii) For cookie adapter: Manually delete the sessions cookies in the browsers affected or programmatically (in case of many users affected): (PHP) How to destroy the session cookie correctly?

iii) For database adapter: TRUNCATE TABLE sessions (delete all records of sessions table)



来源:https://stackoverflow.com/questions/7028509/error-message-while-logging-in-in-kohana

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!