Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7611813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:45:21+00:00 2026-05-31T01:45:21+00:00

This is in a controller class LandingPage extends CI_Controller { public function startEncryptedSession(){ $this->load->library(‘session’);

  • 0

This is in a controller

class LandingPage extends CI_Controller {
    public function startEncryptedSession(){
    $this->load->library('session'); 
    $this->load->library('encrypt');    

    $this->load->view('index', array('session', $this->session));
}


}

How do I load this in the view index

view code

<?php echo $head; ?>

<body>
    <?php echo $guts; ?>
</body>

<?php echo $foot; ?>
<?php echo $session->userdata('session_key'); ?> 

I’m using code igniter MVC

When I load the view, it gives me:

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined variable: session</p>
<p>Filename: views/index.php</p>
<p>Line Number: 8</p>

</div><br />
<b>Fatal error</b>:  Call to a member function userdata() on a non-object 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:45:23+00:00Added an answer on May 31, 2026 at 1:45 am

    You need to pass the variables you want to use to your view.
    Something like this:

    One way:

    In your controller:

    public function startEncryptedSession(){
        $this->load->library('session'); 
        $this->load->library('encrypt');
        $data = array('session_key' => $this->session->userdata('session_key'));
        $this->load->view('index', $data);
    }
    

    In your view:

    <?php echo $session_key; ?> 
    

    Another way:

    In your controller:

    public function startEncryptedSession(){
        $this->load->library('session'); 
        $this->load->library('encrypt');    
        $data = array('session' => $this->session->all_userdata());
        $this->load->view('index', $data);
    }
    

    In your view:

    <?php echo $session['session_key']; ?> 
    

    A word of advice: CodeIgniter’s session class kinda sucks, since it stores data on a cookie and has a very low limit of data size (or at least that was how it worked last time I checked)… so you might want to handle it using PHP’s default session functions or creating a class of your own. But I’ll leave that for you to check, since it isn’t what you were asking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is what I have: class Calendar extends CI_Controller { public $extension; function __construct()
I have got this controller: class Start extends CI_Controller{ var $base; var $css; function
I have a MY_Controller class with this property: class MY_Controller extends CI_Controller { public
I have this controller in Code Igniter that begins with class MyController extends CI_Controller
This is my form class Admin_Form_RoomtypeForm extends Zend_Form { public function init() { $name
I've this controller public class AdminController : Controller { private IAdministratorService _administratorService; public AdminController(IAdministratorService
I got a ASP.NET MVC controller like this [Authorize] public class ObjectController : Controller
Ok i have this controller: class ExampleController extends AppController { var $name = 'Example';
I currently have this: Hotels Controller class HotelsController extends AppController { var $name =
code is like this: @Controller public class TestController { @RequestMapping(value = /testerror, method =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.