Welcome Guest, Not a member yet? Register   Sign In
sessions using database .. ci userguide .. i get an error
#1

[eluser]pendalpusher[/eluser]
I am trying to implement the sessions using database as described in the user guide

http://ellislab.com/codeigniter/user-gui...sions.html

is says the basic table is as follows

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)
);

when i make the table this way .. i get this error

Code:
A Database Error Occurred

Error Number:

ERROR: null value in column "user_data" violates not-null constraint

INSERT INTO "ci_sessions" ("session_id", "ip_address", "user_agent", "last_activity") VALUES ('9c29563e42db1cac999b55d758cd391f', '192.168.1.123', 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/2010010', 1308901391)

Filename: libraries/Session.php

Line Number: 327

obviously when i change the settings to the user_data field to allow null, it works.

Is this an error within the user guide? or I am missing something and using this incorrectly?

any help would be great.

thanks,
C
#2

[eluser]WanWizard[/eluser]
In MySQL, you can't define a default for a TEXT field. And as it's also defined as NOT NULL, you'll get this violation when a new session is created (as you can see, the insert does not define the 'user_data' field).

Remove the NOT NULL from the user_data field to solve this problem.
#3

[eluser]pendalpusher[/eluser]
thanks. I just wanted to make sure i wasn't missing something before I moved on.

I appreciate the confirmation.
C
#4

[eluser]InsiteFX[/eluser]
New Sessions table!
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(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.

InsiteFX
#5

[eluser]pmoroom[/eluser]
[quote author="InsiteFX" date="1309472004"]New Sessions table!
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(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.

InsiteFX[/quote]

I noticed you increased the size of user_agent. I had to do the same thing with FF 5 as the agent name was longer than the default.
#6

[eluser]InsiteFX[/eluser]
I did not increase it the Reactor Core Team did, but they just documented it a couple of days ago. But even varchar(120) is to small for all user_agent strings IE will break it now. I think it should be varchar(255).

InsiteFX
#7

[eluser]pmoroom[/eluser]
Okay good I was going to post it today, but I won't now.
#8

[eluser]osci[/eluser]
http://stackoverflow.com/questions/65492...string-get

I believe the second answer (the accepted one) describes the length issue better.

Also later on that post
Quote:"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; YPC 3.2.0; SearchSystem6829992239; SearchSystem9616306563; SearchSystem6017393645; SearchSystem5219240075; SearchSystem2768350104; SearchSystem6919669052; SearchSystem1986739074; SearchSystem1555480186; SearchSystem3376893470; SearchSystem9530642569; SearchSystem4877790286; SearchSystem8104932799; SearchSystem2313134663; SearchSystem1545325372; SearchSystem7742471461; SearchSystem9092363703; SearchSystem6992236221; SearchSystem3507700306; SearchSystem1129983453; SearchSystem1077927937; SearchSystem2297142691; SearchSystem7813572891; SearchSystem5668754497; SearchSystem6220295595; SearchSystem4157940963; SearchSystem7656671655; SearchSystem2865656762; SearchSystem6520604676; SearchSystem4960161466; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Hotbar 10.2.232.0; SearchSystem9616306563; SearchSystem6017393645; SearchSystem5219240075; SearchSystem2768350104; SearchSystem6919669052; SearchSystem1986739074; SearchSystem1555480186; SearchSystem3376893470; SearchSystem9530642569; SearchSystem4877790286; SearchSystem8104932799; SearchSystem2313134663; SearchSystem1545325372; SearchSystem7742471461; SearchSystem9092363703; SearchSystem6992236221; SearchSystem3507700306; SearchSystem1129983453; SearchSystem1077927937; SearchSystem2297142691; SearchSystem7813572891; SearchSystem5668754497; SearchSystem6220295595; SearchSystem4157940963; SearchSystem7656671655; SearchSystem2865656762; SearchSystem6520604676; SearchSystem4960161466; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"

Wow @.NET framework!!!!
managed to reach 1500+ characters!!!!!!
I lolled and I cried soooo much when I saw that. Thanks god I'm not programming in net!!!!
#9

[eluser]InsiteFX[/eluser]
Ya, I use to program in C# .NET a few years ago. It's a pain in the A$$

InsiteFX
#10

[eluser]pendalpusher[/eluser]
i did some digging through and at I think CI (2.0.2). is already truncating the user_agent to 50 chars.

starts around line 316 in my system/libraries/Session.php
Code:
$this->userdata = array(
    'session_id'    => md5(uniqid($sessid, TRUE)),
    'ip_address'    => $this->CI->input->ip_address(),
    'user_agent'    => substr($this->CI->input->user_agent(), 0, 50),
    'last_activity'    => $this->now
    );
FYI -- I also checked an older version of CI ~1.7.something, and it has the same substr() call.

So I would assume setting it back to varchar(50) would work correct?




Theme © iAndrew 2016 - Forum software by © MyBB