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 7686373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:27:55+00:00 2026-05-31T19:27:55+00:00

I am using CodeIgniter with version 2.1.0. I want to use Hooks for login

  • 0

I am using CodeIgniter with version 2.1.0. I want to use Hooks for login authentication. That means I want in every controller check the session data if loggedin or not. So I want to use hooks. I do the following code for doing that:

In config file

$config['enable_hooks'] = TRUE;

In file hooks.php

$hook['post_controller_constructor'][] = array(
                               'class'    => 'SessionData',
                               'function' => 'initializeData',
                               'filename' => 'loginHelper.php',
                               'filepath' => 'hooks',
                               'params'   => array()
                               );

In file loginHelper.php

class SessionData{
    var $CI;

    function __construct(){
        $this->CI =& get_instance();
    }

    function initializeData() {

        // This function will run after the constructor for the controller is ran
        // Set any initial values here
        if (!$this->session->userdata('username')) { // This is line 13
            redirect('login');
        }
    }
}

But it throws the following error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: SessionData::$session

Filename: hooks/loginHelper.php

Line Number: 13

How can I solve this?

  • 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-31T19:27:56+00:00Added an answer on May 31, 2026 at 7:27 pm

    “Called very early during system execution. Only the benchmark and hooks class have been loaded at this point…“

    You should load all libraries and models manually that you use inside Hook:

    if (!isset($this->CI->session))
    {
        $this->CI->load->library('session');
    }
    

    And use $this->CI->session->userdata() instead of $this->session->userdata().

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

Sidebar

Related Questions

I have an Codeigniter app (using version 2.1.0) that is writing a transaction to
I am using Tank Auth authentication library with Codeigniter 2.0.3 (one version before the
I want to post/tweet to my twitter account using my website developed using codeigniter(version
I'm using CodeIgniter and I got a model that fetches let's say all recipes
I'm using CodeIgniter with CodeIgniter sessions that are stored in a MySQL database. I
I am using the build in Codeigniter Agent detection library and that outputs the
I have got a little problem using the CodeIgniter route function. I use the
Using the latest 1.x (1.7.3) version of CodeIgniter, I get 404 errors on gclid
I'm using a reCaptcha class (the one that's included in the Tank Auth authentication
Anyone using CodeIgniter use automated unit testing? Seems the way CodeIgniter's guy do unit

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.