Accessing session data in another controller gives error

Rizwan Gohar
public function LoginUser()
{

    $this->form_validation->set_rules('email', 'Email', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required');
    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('login');
    }
    else 
    {

        $data['Email']=$this->input->post('email');
        $data['Password']=$this->input->post('password');
        $result=$this->UserAccount_model->LoginUser($data);
        if($result)
        {

            $session_data = array(
            'sesid' => $result[0]->id,
            'sesname' => $result[0]->Name,
            'sesemail' => $result[0]->Email);

            // Add user data in session
            $this->session->set_userdata('logged_in', $session_data);

            $url=base_url()."UserAccount/LoggedIn";

              header("Location:$url");
         }

Now i am accessing session data in photo controller

public function LikePhoto()
{
    $Id=$this->uri->segment(3);
    $UserId=$this->$session_data['sesid'];
    print($UserId);
    exit();

but this gives error

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: session_data

Filename: controllers/Photo.php

Line Number: 55

B. Desai

In CI to get session data you have to use $this->session->userdata()

So change your code to:

$UserId=$this->session->userdata('logged_in')['sesid'];

EDIT If you want to store data from array only add array variable in session

So change

$this->session->set_userdata('logged_in', $session_data);

To

$this->session->set_userdata($session_data);

And to retrieve :

$UserId=$this->session->userdata('sesid');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Accessing one controller variable in another controller in Rails

From Dev

Not accessing the date picker gives the conversion error

From Dev

Rails Generate Controller gives me load error

From Dev

Protractor gives "Unable to start a WebDriver session" error

From Dev

Accessing function within another controller in Laravel 4

From Dev

Laravel controller gives not found error

From Dev

WeBrick does not bootup, gives an error white accessing new rails app

From Dev

Accessing a service from a controller in another file in AngularJS

From Dev

Accessing data from one controller to another

From Dev

How to Session variable pass one controller to another controller using codeigniter

From Dev

Accessing the variable from another model in my controller

From Dev

Error in accessing json data

From Dev

Fetching session value from webmethod gives error

From Dev

Accessing data from another controller in Rails

From Dev

Post from View to Controller works but gives an error

From Dev

angularjs - accessing a factory from a controller in another module

From Dev

Rails Generate Controller gives me load error

From Dev

Accessing session data in ring middleware

From Dev

Accessing function within another controller in Laravel 4

From Dev

Accessing session data in view in Code Igniter

From Dev

WeBrick does not bootup, gives an error white accessing new rails app

From Dev

Accessing Digital Ocean server gives an error message while you SSH

From Dev

Accessing a service from a controller in another file in AngularJS

From Dev

How to Session variable pass one controller to another controller using codeigniter

From Dev

Error accessing Excel data table

From Dev

error in accessing action view of the controller

From Dev

Accessing json elements gives undefined error

From Dev

Django 1.10: accessing session data after redirect

From Dev

findViewById() in another class gives error

Related Related

  1. 1

    Accessing one controller variable in another controller in Rails

  2. 2

    Not accessing the date picker gives the conversion error

  3. 3

    Rails Generate Controller gives me load error

  4. 4

    Protractor gives "Unable to start a WebDriver session" error

  5. 5

    Accessing function within another controller in Laravel 4

  6. 6

    Laravel controller gives not found error

  7. 7

    WeBrick does not bootup, gives an error white accessing new rails app

  8. 8

    Accessing a service from a controller in another file in AngularJS

  9. 9

    Accessing data from one controller to another

  10. 10

    How to Session variable pass one controller to another controller using codeigniter

  11. 11

    Accessing the variable from another model in my controller

  12. 12

    Error in accessing json data

  13. 13

    Fetching session value from webmethod gives error

  14. 14

    Accessing data from another controller in Rails

  15. 15

    Post from View to Controller works but gives an error

  16. 16

    angularjs - accessing a factory from a controller in another module

  17. 17

    Rails Generate Controller gives me load error

  18. 18

    Accessing session data in ring middleware

  19. 19

    Accessing function within another controller in Laravel 4

  20. 20

    Accessing session data in view in Code Igniter

  21. 21

    WeBrick does not bootup, gives an error white accessing new rails app

  22. 22

    Accessing Digital Ocean server gives an error message while you SSH

  23. 23

    Accessing a service from a controller in another file in AngularJS

  24. 24

    How to Session variable pass one controller to another controller using codeigniter

  25. 25

    Error accessing Excel data table

  26. 26

    error in accessing action view of the controller

  27. 27

    Accessing json elements gives undefined error

  28. 28

    Django 1.10: accessing session data after redirect

  29. 29

    findViewById() in another class gives error

HotTag

Archive