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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:33:15+00:00 2026-05-25T17:33:15+00:00

To check If a user is logged in I need to pull off a

  • 0

To check If a user is logged in I need to pull off a pretty long if-statement and then redirect the user depending if the user is logged in or not. I think a custom function like

if (logged_in()) { redirect }

Would be more appropriative. But building a library for one function seems unnecessary to me. 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-05-25T17:33:15+00:00Added an answer on May 25, 2026 at 5:33 pm

    I need to pull off a pretty long if-statement, but building a library for one function seems unnecessary

    It’s not at all “unnecessary”, neither is it strictly “necessary”, but it’s probably a good idea to create a library/class for this.

    If you have a lot of logic you need to work with, “a pretty long if-statement” for example, using a class can help you break this down into smaller pieces and make the logic more manageable. If you only need to call one public method of the class, like $this->auth->is_logged_in(), there’s nothing wrong with that, then you can create a small helper file or wrapper function to call the method, and put the redirect logic there instead of the class. Something like this perhaps:

    // Make sure your "auth" library is autoloaded or load it here
    function logged_in($redirect = TRUE)
    {
        $CI =& get_instance();
        $logged_in = $CI->auth->is_logged_in();
    
        // Redirect the user...
        if ( ! $logged_in AND $redirect)
        {
            redirect('somewhere/else/');
        }
    
        // Or just check if they are logged in
        return $logged_in;
    }
    

    Using a class/library has many benefits, and with something as complicated as user authorization you will benefit greatly from taking advantage of it, especially once your project starts to expand and you need more utility.

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

Sidebar

Related Questions

in the project I'm creating I need to check if the user is logged
i want code to check whether the user in logged in or not. I
how can I check if a user (not the one currently logged in) is
I need to check that a user have logged in and been authenticated before
I need to perform a couple of actions when the user is logged off
Below is the code to check whether user is logged in or not ,
I need to check if sure is logged in user login to account.domain.com system
I am not able to check if user is logged in or not in
how can i check if a user is logged in in user control with
I currently have code in my ApplicationController to check if a user is logged

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.