1
votes

I'm building small blog-like system for school. I need to store some data in cookie as well as save session in db and cookie. Codeigniter (CI) is saving session in database and cookie by it self if you set it on config/config.php as well as loading session library in config/autoload.php

Goal: I need to set session, email and username in cookie after login and later get it back. Kill cookie and all db data on cookie expire or logout.

Problem: CI is creating new session record in to db every single time when i reload page. it dosent realy matter which page, even on refresh it makes new INSERT in to DB.

Question: How should I stop CI of making autsave and make it save session only after login and kill session after logout?

1

1 Answers

3
votes

Did you create the Session CI Table with this exact syntax?? I noticed that many problems comes with it.

--
-- Table structure for CodeIgniter ci_sessions.
--
DROP TABLE IF EXISTS `ci_sessions`;

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
  `session_id`    varchar(40)           DEFAULT '0' NOT NULL,
  `ip_address`    varchar(16)           DEFAULT '0' NOT NULL,
  `user_agent`    varchar(120)                      NOT NULL,
  `last_activity` int(10)      unsigned DEFAULT 0   NOT NULL,
  `user_data`     text,
  PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

-- -------------------------------------------------------------
--  `user_data` text,       COMMENT - maximum length of 65535 characters.
--  `user_data` mediumtext, COMMENT - maximum length of 16777215 characters.
--  `user_data` longtext,   COMMENT - maximum length of 4294967295 characters.