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

  • Home
  • SEARCH
  • 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 9192531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:56:49+00:00 2026-06-17T20:56:49+00:00

How do I change the content for a user when he logs in? I

  • 0

How do I change the content for a user when he logs in? I mean like enabling voting, changing “login” to “logout” etc.
What I think to do is to start the session when user logs in (I am preferring to start session only when user logs in, not all the time). Then add data to the session’s cookie like-

//controller 
$moredata = array(
    'username'  => $this->username,
    'login' => TRUE
);
 $this->session->set_userdata($modedata);
//redirect

Then in the other controller, where he has been redirected I check the following-

$login = $this->session->userdata('login');
     if ($login==TRUE)

Depending on the ‘if’ condition I will pass a variable to the view, with the help of that variable I will forward only the div/sections which should be shown to a logged-in user.
The problem is, while performing the above comparison Codeigniter shows following error (remember I haven’t added ‘session’ in autoload array yet)

Message: Undefined property: NameOfController::$session

And If I set following in the autoload file

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

then the “if ($login==TRUE)” comparison always shows FALSE.
What should I do?

  • 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-06-17T20:56:50+00:00Added an answer on June 17, 2026 at 8:56 pm

    If I were you, I’d place all your session checks in a base controller which all your other main controllers extend. This allows you to keep things DRY:

    class BaseController extends CI_Controller {
    
       public function __construct()
       {
          parent::__construct();
       }
    
       public function isLoggedIn()
       {
          // Will return true or false
          return $this->session->userdata('login');
       }
    
    }
    

    And in one of your functional controllers (the example below handles users):

    class UserController extends BaseController {
    
       public function __construct()
       {
          parent::__construct();
       }
    
       public function profile()
       {
          // Redirect if not logged in
          if (!$this->isLoggedIn()) {
             $this->redirect('some/other/page')
          }
       }
    
       public function register()
       {
          // Show different HTML if not logged in
          $data = array(
             'isLoggedIn' => $this->isLoggedIn()
          );
          $this->load->view('register', $data);
       }
    
    }
    

    The second method in UserController allows you to render different content in your view:

    <? if ($isLoggedIn): ?>
       <p>You're logged in!</p>
    <? else: ?>
       <p>Not logged in</p>
    <? endif; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to update (change the content) some part of the webpage without
I'm trying to change the content of the menu whenever the user clicks a
I'm trying to change auth token in session. Scenerio is; An anonymouse user reaches
How can I change cachable content so that the user will immediately get the
Target: When user give valid login and password -> (JFrame - Destroy login content)
I want to change content of a Button in XAML using a DataTrigger. Conditionally
I want to dynamically change content , by following code. localStorage.removeItem(some key); but current
This code work. It create a document kind entry. I only change content of
How can I change the content of my facebook share option? my web app
How would I change the content of a <textarea> element with JavaScript? I want

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.