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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:51:29+00:00 2026-05-23T15:51:29+00:00

I have a controller user in my codeigniter application. This controller has a function

  • 0

I have a controller “user” in my codeigniter application. This controller has a function called logged_user_only():

public function logged_user_only()
    {
        $is_logged = $this -> is_logged();
        if( $is_logged === FALSE)
        {
            redirect('user/login_form');
        }
    }

As this function calls another function called is_logged(), which just checks if the session is set, if yes it returns true, else returns false.

Now if i place this function in the begining of any function within same controller, it will check if the user is not logged, it will redirect to login_form otherwise continue. This works fine.
For example,

public function show_home()
    {
        $this -> logged_user_only();
        $this->load->view('show_home_view');
    }

Now I would like to call this logged_user_only() function in a function of another controller to check if the user is logged in or not?

PS. If this can not be done, or is not recommended, where should i place this function to access in multiple controllers? Thanks.

  • 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-23T15:51:29+00:00Added an answer on May 23, 2026 at 3:51 pm

    Why not extend the controllers so the login method is within a MY controller (within the core folder of your application) and all your other controllers extend this. For example you could have:

    class MY_Controller extends CI_Controller {
        public function is_logged()
        {
            //Your code here
        }
    }
    

    and your main controllers could then extend this as follows:

    class Home_Controller extends MY_Controller {
        public function show_home()
        {
             if (!$this->is_logged()) {
               return false;
             }
        }
    }
    

    For further information visit: Creating Core System Classes

    New link is here:
    https://www.codeigniter.com/user_guide/general/core_classes.html?highlight=core%20classes

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

Sidebar

Related Questions

I have a codeigniter application.This is my code in view page. function click_next(){ var
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have a directory in the root of my codeigniter application called /css it
I'm currently working on a project with Codeigniter. I have one controller called Cat
I have a controller user with a method login For some reason, when I
I have a controller with an action method as follows: public class InventoryController :
I have multiple controller actions that takes an id public ActionResult Get(int? id) {
I followed this tutorial: http://codeigniter.com/wiki/Internationalization_and_the_Template_Parser_Class/ The controller that loads the language is this one:
I have a CodeIgniter application, but one of my controllers must call a data

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.