Welcome Guest, Not a member yet? Register   Sign In
New CI 1.7 session class database error
#21

[eluser]CIfan1000[/eluser]
Well, I am sorry to add to this, but could you clarify this please:

I now have $config['sess_use_database'] = TRUE; in config.php.

I took a look at the cookie and it is:

a:4:{s:10:"session_id";s:32:"3ed77432e5af75c28d6d94670ed2858c";s:10:"ip_address";s:9:"127.0.0.1";s:10:"user_agent";s:50:"Mozilla/5.0+(Windows;+U;+Windows+NT+5.1;+en-US;+rv";s:13:"last_activity";s:10:"1224992448";}b2895c57934687268f67eddea8727c38

In other words, the ip address, user_agent, and last_activity are still in the cookie AND they are in the ci_sessions table - could someone clarify why please? I was under the impression that these session variables would only be in the ci_sessions table, not in the cookie.

Thanks!
#22

[eluser]Randy Casburn[/eluser]
Hi,

1) When you re-created your table without 'NOT NULL' that fixed your DB problem.
-- Please do not be worried about this as your application will be fine and no harm will be done
2)
Quote:I was under the impression that these session variables would only be in the ci_sessions table, not in the cookie.

The values are stored in both places.

If you're interested in the specifics, open the libraries/sessions.php file. At line 298 you'll find the sess_create() method. In this method $this->user_data is defined. The last statement in the method is a call to $this->set_cookie(). That method is at line 634. In the set_cookie() method $cookie_data is assgined the value of $this->user_data. Then, the $cookie_data is written to the cookie.

That's what takes place.
---

So the bottom line is this: You've solved your problem but perhaps discovered an unexpected result along the way.

Hope this is has all been helpful.

Randy
#23

[eluser]CIfan1000[/eluser]
Ok Randy,

First of all, thank you for spending all this time with me to address this issue.

Thanks for your reassurance about being able to use the table in this way without any problems.

Take care and good coding!
#24

[eluser]Randy Casburn[/eluser]
You are very welcome! I'm glad I could help.

You'll find that everyone in these forums is very helpful.

Take Care,

Randy
#25

[eluser]Unknown[/eluser]
The problem is that MySQL is running in Strict mode (http://dev.mysql.com/doc/refman/5.0/en/s...-mode.html). Under strict mode, MySQL doesn't allow not null fields to be left empty. You have 3 options: 1) Disable strict mode in MySQL. I wouldn't recommend this if you are writing an application to redistribute. You never know what settings the other systems have. 2) Setting a default value for fields that are set as not null. For numeric fields you can set the value to 0. For text field, you can't set a default value so you will need to set it to null. 3) When inserting values to the database what you can do is insert an empty string for text fields.

INSERT INTO test
(varaible, value, empty_field)
VALUES ('test', 'hello', ''),
('text2', '', '');

Hope this helps.
#26

[eluser]guilherme.muller[/eluser]
Hi there, thought I could contribute with some notes as well...

I had trouble with MySQL and the new Sessions library too. Had to set the user_data column to allow NULL values to work. BUT, there was another problem that was causing the session to instantly logout.

So, if you were using a check with the strict equality or strict inequality operator, like this:

if ($this->session->userdata('logged') !== TRUE) {

It will not work anymore, because Codeigniter serializes it as '1' instead of TRUE. If you use cookies, maybe it will still work. For my sessions to work I had to change the '!==' to '!='.
#27

[eluser]CIfan1000[/eluser]
Thanks JayBachatero and guilherme.muller - your posts are helpful!
#28

[eluser]a&w[/eluser]
So would y'all say there's a bug in the current user guide docs on this then? Sadly I fear I may be responsible:
http://ellislab.com/forums/viewthread/90325/

I'm pretty sure I had tested that before I posted, so I'm not sure if there's been a change somewhere else in the code to cause the problem. Anyway, I too am struck by this problem.

Is it preferable/acceptable to use "NULL" instead of "NOT NULL" or go ahead and set 'default 0' or something?
#29

[eluser]a&w[/eluser]
Ok, I guess you can't specify a default:
http://dev.mysql.com/doc/refman/5.1/en/blob.html

NULL it is?!

If anyone agrees this is a bug in the user guide perhaps strike me down in that last link.
#30

[eluser]Unknown[/eluser]
Hi guys,when I using SQL Server as my database, I meet this bug again just as you had descript. Here is my solution:

=======================================================
--- system\libraries\Session.php 2008-10-18 13:36:48.000000000 +0800
+++ application\libraries\Session.php 2008-11-16 12:15:39.046875000 +0800
@@ -14,6 +14,7 @@
*/

// ------------------------------------------------------------------------
+define('USER_AGENT_MAX_LENGTH', 196);

/**
* Session Class
@@ -182,7 +183,7 @@
}

// Does the User Agent Match?
- if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50)))
+ if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, USER_AGENT_MAX_LENGTH)))
{
$this->sess_destroy();
return FALSE;
@@ -309,11 +310,11 @@
$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
+ 'user_agent' => substr($this->CI->input->user_agent(), 0, USER_AGENT_MAX_LENGTH),
+ 'last_activity' => $this->now,
+ 'user_data' => ''
);

-
// Save the data to the DB if needed
if ($this->sess_use_database === TRUE)
{
=======================================================

As you can see, I had make two changes:
1),change the length of 'USER_AGENT',50 is really bother me sometimes;(Of course you have to change your table's definition to adapt your setting first)
2),Add default 'user_data' value when insert new session record.

It is work fine for me,if you have any issue,please contact me.Smile




Theme © iAndrew 2016 - Forum software by © MyBB