• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
session in 3.0.3 not saving userdata

#1
I had sessions working fine in 2.x version of CI. I used to save them on client machine, but I've decided to use database. I've setup table and everything else in config file. Problem is I never get any errors. Session library is in autoload config file. In my model I use following code to put data into session:


PHP Code:
$this->session->set_userdata(array(
 
 'email' => $email,
 
 'is_logged_in' => 1)
); 

But when I try to use:


PHP Code:
var_dump($this->session->userdata()); 

I get following output:

Code:
array(1) { ["__ci_last_regenerate"]=> int(1448664996) }

nothing is added to session, no errors showing up. Can anyone help?
Reply

#2
I've test, but it okay ??

$this->load->library('session');
$this->session->set_userdata(array('email'=>'[email protected]', 'is_login'=>1));
$session = $this->session->userdata();
var_dump($session);

array(3) { ["__ci_last_regenerate"]=> int(1448684634) ["email"]=> string(17) "[email protected]" ["is_login"]=> int(1) }
Reply

#3
I've solved this problem. Problem was that my cookie was overriding database session. In config file if using database for session, this line cannot have value:

$config['sess_cookie_name'] = 'mydomain';

In order for session to work using database, that value has to be empty:

$config['sess_cookie_name'] = '';

If it is not empty, CI will default to cookies for your session. This does not mean you cannot use cookies. You just have to loaded them via helper and they will work just fine.
Reply

#4
(11-27-2015, 11:07 PM)zuboje Wrote: I've solved this problem. Problem was that my cookie was overriding database session. In config file if using database for session, this line cannot have value:

$config['sess_cookie_name'] = 'mydomain';

In order for session to work using database, that value has to be empty:

$config['sess_cookie_name'] = '';

If it is not empty, CI will default to cookies for your session. This does not mean you cannot use cookies. You just have to loaded them via helper and they will work just fine.

Not true.
Reply

#5
(11-28-2015, 05:14 AM)Narf Wrote:
(11-27-2015, 11:07 PM)zuboje Wrote: I've solved this problem. Problem was that my cookie was overriding database session. In config file if using database for session, this line cannot have value:

$config['sess_cookie_name'] = 'mydomain';

In order for session to work using database, that value has to be empty:

$config['sess_cookie_name'] = '';

If it is not empty, CI will default to cookies for your session. This does not mean you cannot use cookies. You just have to loaded them via helper and they will work just fine.

Not true.

It is 100% sure since that resolved my problem.
Reply

#6
(11-28-2015, 11:01 AM)zuboje Wrote:
(11-28-2015, 05:14 AM)Narf Wrote:
(11-27-2015, 11:07 PM)zuboje Wrote: I've solved this problem. Problem was that my cookie was overriding database session. In config file if using database for session, this line cannot have value:

$config['sess_cookie_name'] = 'mydomain';

In order for session to work using database, that value has to be empty:

$config['sess_cookie_name'] = '';

If it is not empty, CI will default to cookies for your session. This does not mean you cannot use cookies. You just have to loaded them via helper and they will work just fine.

Not true.

It is 100% sure since that resolved my problem.

No, it's not.

The only thing you know is that setting $config['sess_cookie_name'] to an empty string somehow made your application work. Everything else you just made up, and what you've made up doesn't even make sense.

Your problem is a simple cookie name collision; setting $config['sess_cookie_name'] to anything but the name you've used with CI2 would resolve your problem. Setting it to an empty string just makes it use the session.name value from your php.ini.
Reply

#7
(11-28-2015, 03:08 PM)Narf Wrote:
(11-28-2015, 11:01 AM)zuboje Wrote:
(11-28-2015, 05:14 AM)Narf Wrote:
(11-27-2015, 11:07 PM)zuboje Wrote: I've solved this problem. Problem was that my cookie was overriding database session. In config file if using database for session, this line cannot have value:

$config['sess_cookie_name'] = 'mydomain';

In order for session to work using database, that value has to be empty:

$config['sess_cookie_name'] = '';

If it is not empty, CI will default to cookies for your session. This does not mean you cannot use cookies. You just have to loaded them via helper and they will work just fine.

Not true.

It is 100% sure since that resolved my problem.

No, it's not.

The only thing you know is that setting $config['sess_cookie_name'] to an empty string somehow made your application work. Everything else you just made up, and what you've made up doesn't even make sense.

Your problem is a simple cookie name collision; setting $config['sess_cookie_name'] to anything but the name you've used with CI2 would resolve your problem. Setting it to an empty string just makes it use the session.name value from your php.ini.

Or have you ever thought that you can try reproducing this or that this could be a CI bug? Instead of attacking me, please be nice this forum is place for people to discuss. I've asked question, found out the problem and posted resolution. If you don't have resolution please do not comment. Or if you are 100% sure I am wrong please post references to docs that are saying opposite of what I wrote.
Reply

#8
(11-29-2015, 04:18 PM)zuboje Wrote: Or have you ever thought that you can try reproducing this or that this could be a CI bug?

Reproduce? Did you even read what I wrote?

(11-29-2015, 04:18 PM)zuboje Wrote: Instead of attacking me, please be nice this forum is place for people to discuss.

I pointed out that you gave a totally false explanation of how CI works. If you treat that as an attack, then you're incapable of participating in a discussion.

(11-29-2015, 04:18 PM)zuboje Wrote: I've asked question, found out the problem and posted resolution.

You found a resolution (and probably by accident, I would say), and there's nothing wrong with that.
But you present it as the solution; and you didn't find the problem. You just guessed what the problem is and your guess was wrong. Yet, you present it as a fact, which it is not. As I said, it doesn't even make sense, which is one of the reasons why I can say with 100% certainty that you made it up.

(11-29-2015, 04:18 PM)zuboje Wrote: If you don't have resolution please do not comment.

I already gave you a resolution - read the last paragraph of my previous post - but that's not why we're having this argument.

(11-29-2015, 04:18 PM)zuboje Wrote: Or if you are 100% sure I am wrong please post references to docs that are saying opposite of what I wrote.

I'm giving this one back at you: the documentation says absolutely nothing to prove your point.

And I know that because I wrote it. I also wrote the session library.
I didn't just jump in to say that you're wrong for no reason at all ... I did it because I know, more than 100%, that what you wrote is wrong.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.