1

Hi i have this new type of problem it is that my codeignitor sessions not work in other functions in controller

for example my login3 function

\\Data is coming from here fine
foreach($query as $row)
{

 $name = $row->name;
 $id = $row->id;
$dmail = $row->email;

}

 if(isset($dmail))
{



  $arr = array();


 $arr['name'] = $name;
 $arr['id'] = $id;
 $arr['email'] = $email;


 $this->session->set_userdata("facebooker",$arr);

 $this->load->model('Gift');



$this->load->library('session');

$der = $this->session->userdata("facebooker");


 $arrr = array();



 $arrr['unamer'] = $der['name'];

 $arrr['ids'] = $der['id'];
 $arrr['email'] = $der['email'];

//After loading the views all data shows fine

$this->load->view("gifttoday/header",$arrr);
$this->load->view("gifttoday/welcome",$arrr);

 }

But when i call the same session in this function but in same controller it shows no data

function profileselect()
{
$this->load->model('Gift');

 $var =array();

 $this->load->library('session');
 // Here i call this session but no data
  $mer = $this->session->userdata("facebooker");
 // When i print all the values of $mer it shows empty array 
 var_dump($mer);
/**
$this->load->view("gifttoday/header",$arrr);
$this->load->view("gifttoday/profilev",$arrr);
**/
  }

I have searched this problem and my people are having this problem with codeignitor sessions but non of the fixes worked for me can any body help me with this.

2
  • its because youre setting the session before loading the session library, you must load first the library before setting the session. Commented Dec 29, 2013 at 17:37
  • load session library in constructor Commented Dec 29, 2013 at 17:37

2 Answers 2

1

Better is to load session Library in constructor

public function __construct() 
    {

      $this->load->library('session');
}

Or enable session Library in config.php

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks man know i just opened my seesion library in the construnctor once and all started working
enable it inside config.php or inside autoload.php?
1

You're calling the library after setting the session data which probably overwrites it (in case you already had the session library loaded in the first place):

So this:

$this->session->set_userdata("facebooker",$arr);
$this->load->model('Gift');

$this->load->library('session');

Should be this:

$this->load->library('session');
$this->session->set_userdata("facebooker",$arr);
$this->load->model('Gift');

But, if you intend to use the session library in several places in your app, it's a better idea to autoload it...

Edit this line in file application/config/autoload.php

$autoload['libraries'] = array('session',...);

and then just avoid loading it manually when needed.

2 Comments

Thanks man know i just opened my seesion library in the construnctor once and all started working
Thanks man know i just opened my seesion library in the construnctor once and all started working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.