Welcome Guest, Not a member yet? Register   Sign In
Can't get $this->session->set_userdate to work
#1

[eluser]Volder[/eluser]
Hello, guys.
I'm new on the forum and with codeigniter either.
And I'm trying to set session data and use it on the different web-page.

So I wrote a simple controller to show what an error I'm facing:
Code:
<?php
class Test extends Controller{

  function index()
   {  
      echo 'Before defining:'.$this->session->userdata('val');
      $this->session->set_userdata('val',100);
      echo '<br/>After defining:'.$this->session->userdata('val');
      redirect('test/ttt');
   }

  function ttt()
  {
    echo 'On a new page: '.$this->session->userdata('val');
  }
}
?&gt;

If I erase redirect function call on pahe '/test' - I see that session variable val is defined with a value 100. So seems correct.

But after redirect to a new page '/test/ttt' - I see a message on the screen:
"On a new page: " and that's all.

So seems that session data is not stored correctly.
Why can this happen?

Thanks.
#2

[eluser]Randy Casburn[/eluser]
Hi Volder - First things first - You actually DO have a constructor in this controller right? I'm hoping you took it out for brevity?
#3

[eluser]Sumon[/eluser]
I get everything perfect with your same code. and i hope you not miss to load session library for ttt() function.
However you may try with
Code:
redirect('test/ttt' , 'refresh');
#4

[eluser]Volder[/eluser]
[quote author="Randy Casburn" date="1221165000"]Hi Volder - First things first - You actually DO have a constructor in this controller right? I'm hoping you took it out for brevity?[/quote]

no I don't have a constructor in this controller as it is not needed.
Library 'session' is included into autoload configuration file.

[quote author="Sumon" date="1221165000"]I get everything perfect with your same code.[/quote]
Well, I checked on the other machine and it worked like a charm.
So I make a conclusion - that something wrong on my PC.

I checked in both FF3 and IE7 and in both it has not worked.
While cookies are enabled.

So do anybody can give a promt in which direction to investigate this problem?
#5

[eluser]Skuja[/eluser]
There are other users that have experienced such problems with CI session.
I would suggest you to try Native Session library. Although it is not a good solution, but it helped me. Also you could search in this forum about this, maybe someone has found the problem and better solution without a need to load external library.
#6

[eluser]Randy Casburn[/eluser]
While not required, just for giggles, please add:

Code:
function Test()
{
   parent::Controller();
}

to your controller. Report the results.

Randy
#7

[eluser]Volder[/eluser]
[quote author="Randy Casburn" date="1221237191"]While not required, just for giggles, please add:
Code:
function Test()
{
   parent::Controller();
}
to your controller. Report the results.
Randy[/quote]
nope, it doesn't help. I've tried it after your first post.

[quote author="Skuja" date="1221237191"]I would suggest you to try Native Session library.[/quote]I'm inclining to use OBSession. Still have not tried it - but going to write here whether it would help me. Thanks.
#8

[eluser]Volder[/eluser]
tried both additional libraries:

OBSession - have not helped.

But with Native Session library I have solved my problem.

Thanks.
#9

[eluser]GSV Sleeper Service[/eluser]
stick with "native sessions" - I (and many others) have found CI Sessions to be unreliable when using IE.




Theme © iAndrew 2016 - Forum software by © MyBB