• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not Saving Session

#1
[eluser]ricmen[/eluser]
Hi Everyone I have I little frustrating issue, I have a function in my client_controller called Paid, this function has a validation that retrieves the userId from the
$this->session->userdata("user_session"), and this works for the first time, the weird thing here is when I do a post back to that function the session is cleared, I already check my code and I don't have any unset_session or something that destroy the session, I always load the library $this->load->library("session"). at the beginning of the controller.

any ideas ?


Best Regards


#2
[eluser]InsiteFX[/eluser]
.application/config/autoload.php - autoload the session library under libraries.

#3
[eluser]ricmen[/eluser]
Hi InsiteFX,

Sorry I didn't mentioned but I have the autoload.php with this libraries

$autoload['libraries'] = array('database', 'form_validation','javascript','session');

The weird thing is when I enter to the page, I have this session, then I do another post to the same function and I have the session, but when I do another post to the same function with another action, the session is gone, I think that the session is saved and for some reason in the third post back this is cleared.

any another idea?

Best Regards

#4
[eluser]InsiteFX[/eluser]
Sounds like one of your methods is over writing your session item some place.

Do a var_dump see where it is being over written.

#5
[eluser]ricmen[/eluser]
Yes You are right that was the problem,

My code is something like this


Code:
$userInfo = $this->session->userdata("logged_in");
//here I have some validations with userinfo
if($_POST){
if($_POST["newContract"]){
    $this->session->set_userdata("contract", $contract);
  }else{
    $contract = $this->sesion->userdata("contract");

}

Now I think that I have the problem of save all this in a new object.

do you know what would be the best approach for this?


Best Regards

#6
[eluser]InsiteFX[/eluser]
You could save it into the database or use a registry class to save it. If you search the forums on my name yu will find a couple of them that we posted.

#7
[eluser]noideawhattotypehere[/eluser]
[quote author="ricmen" date="1393253707"]Yes You are right that was the problem,

My code is something like this


Code:
$userInfo = $this->session->userdata("logged_in");
//here I have some validations with userinfo
if($_POST){
if($_POST["newContract"]){
    $this->session->set_userdata("contract", $contract);
  }else{
    $contract = $this->sesion->userdata("contract");

}

Now I think that I have the problem of save all this in a new object.

do you know what would be the best approach for this?


Best Regards
[/quote]
not really related to topic but:
instead of doing x nested ifs, you can just do it like that
Code:
if ($this->input->post('newContract)) {
//what we do if we have post value
} else {
//what we do if we dont
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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