Welcome Guest, Not a member yet? Register   Sign In
CI Session using DB Problem
#1

[eluser]cideveloper[/eluser]
Hey All

So this is not really a question, more of an observation I made yesterday. First time I noticed this. When using CI session and a DB to store data with the following info obtained from the docs.

Code:
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(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text DEFAULT '' NOT NULL,
PRIMARY KEY (session_id)
);

and

Code:
sess_match_useragent = TRUE

Every time I went to any page a new session was created and it was driving me crazy. Never had this problem before.

Solution: user_agent field in DB needs to be a larger varchar. When CI inserted my user_agent it was being truncated due to the small size of the field. Then when Session queries to see if their is an existing session the user agents dont match.

Code:
SELECT *
FROM (`ci_sessions`)
WHERE `session_id` =  '0e90633d2901c711a6efd855c40729fd'
AND `user_agent` =  'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'

my user agent was being stored as "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gec" due to size restrictions.

Anyone else have this problem and think maybe the docs should be changed to reflect

user_agent varchar(255) NOT NULL
#2

[eluser]WanWizard[/eluser]
Report this as an error in the user guide. CI 2.0.2. has extended the size to 120 characters.
#3

[eluser]cideveloper[/eluser]
Its funny I never use the local copy of the user guide. Always the online one. How does one go about reporting this?
#4

[eluser]InsiteFX[/eluser]
You can change the user_data size when creating the table see below.
Code:
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(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text DEFAULT '' NOT NULL, COMMENT <-- this is an error in user guide!
PRIMARY KEY (session_id)
);

// Correct code:
-- --------------------------------------------------------------

--
-- 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(50)                            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.

InsiteFX
#5

[eluser]InsiteFX[/eluser]
Will create a new session every time you load a new page, Set it to FALSE and it will work correct!
Code:
sess_match_useragent = TRUE

InsiteFX
#6

[eluser]cideveloper[/eluser]
Hey InsiteFX

I already changed user_agent varchar(255) NOT NULL. Just the online docs show length 50. Your first reply does not cover this issue. I know it fixes a couple of other problems I have noticed. I always make user_data mediumtext, which covers a lot of data.




Theme © iAndrew 2016 - Forum software by © MyBB