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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:31:20+00:00 2026-06-04T11:31:20+00:00

I am using Tank_auth for user authentication in codeigniter. To check if any user

  • 0

I am using Tank_auth for user authentication in codeigniter. To check if any user is logged in or not, if he is then to get the username and id I need to use the following code in every functions of my controllers, which is very irritating.

 // If any user is logged in get his/her userid or name
    if ($this->tank_auth->is_logged_in()) {

        $data['user_id']    = $this->tank_auth->get_user_id();
        $data['username']   = $this->tank_auth->get_username();
    }

So , I was wondering if I could make life easier by putting the following code inside the function __construct() like following,
but its not working.

Could you please tell me how to get it work?

Thanks in Advance 🙂

     function __construct()
    {
        parent::__construct();

      $this->load->helper('url');
      $this->load->library('tank_auth');


          if ($this->tank_auth->is_logged_in()) {

        $data['user_id']    = $this->tank_auth->get_user_id();
        $data['username']   = $this->tank_auth->get_username();
    }
  }
  • 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-04T11:31:21+00:00Added an answer on June 4, 2026 at 11:31 am

    if you plan to use this array only inside this controller, you can use it like this:

    //outside the functions define the $data as controller class property:
    
    private $data = array();
    
    function __construct()
    {
        parent::__construct();
    
        $this->load->helper('url');
        $this->load->library('tank_auth');
    
    
        if ($this->tank_auth->is_logged_in()) {
            $this->data['user_id']    = $this->tank_auth->get_user_id();
            $this->data['username']   = $this->tank_auth->get_username();
        }
    }
    
    //and then use it like 
    
    function index(){
        $this->load->view("something.php",$this->data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP/CodeIgniter and Tank_Auth library for authentication both on site.com and via
I am using Tank Auth authentication library with Codeigniter 2.0.3 (one version before the
I am using Tank Auth for Codeigniter to facilitate user registration and login. Problem:
I am using Codeigniter PHP Framework with Tank Auth authentication library. In my config
I’m doing the following queries in codeigniter and can’t figure out how to get
I am using Tank Auth for user authentication. I am using the database to
I am using the Tank Auth library for CodeIgniter. When a user is registered,
Iam using default settings for tank_auth installation. When I tried following statement in controller:
I'm using Tank Auth and my project will support two access type: normal user
Using LINQ on collections, what is the difference between the following lines of code?

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.