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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:07:49+00:00 2026-05-29T19:07:49+00:00

Where can I place my global function, which will check, if user is logged

  • 0

Where can I place my “global” function, which will check, if user is logged in?

Because I want to do something like: user is able to browse some pages only when the function isLogged() returns TRUE, and I’d have to use it in some views, that’s why it should be a “global” function, which I can access from anywhere.

Is that possible? Or there is any better solution for 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-29T19:07:51+00:00Added an answer on May 29, 2026 at 7:07 pm

    You should probably put it into a Library, and autoload the library. When you need to use the “logged_in” flag in a view, pass it in from the controller. Example:


    application/libraries/Auth.php

    <?php defined('BASEPATH') OR exit('No direct script access allowed');
    
    class Auth
    {
    
        public function is_logged_in ()
        {
            // Change this to your actual "am I logged in?" logic
            return $_SESSION['logged_in'];
        }
    
    }
    

    application/config/autoload.php

    ...
    $autoload['libraries'] = array(
        ...
        'auth',
        ...
    }
    

    `application/controllers/welcome.php

    <?php ...
    
    public function index ()
    {
        $view_data = array
        (
            'logged_in' => $this->Auth->logged_in()
        );
        $this->load->view('my_view', $view_data);
    }
    

    application/views/my_view.php

    <? echo $logged_in ? 'Welcome back!' : 'Go login!' ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where in this pattern I can place services, about which I some much hear
I have an website where people can place a vote like this: http://mysite.com/vote/25 This
Is it possible to have multiple folders where I can place applications to be
i am using vb.net i just wanna ask if we can place a picture
There are <meta> tags and other things you can place in the <head> of
Can one place an arbitrary program (firefox, openoffice, etc...) in a QX11EmbedContainer? The fllowing
How can I place a form at the bottom-right of the screen when it
How can you place controls on a frame of a WPF window? I took
In how many ways and places can we place comments in CSS? Can the
Joining an existing team with a large codebase already in place can be daunting.

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.