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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:36:13+00:00 2026-05-30T18:36:13+00:00

When user logins or when he registers, his $_SESSION[‘username’] gets the value of his

  • 0

When user logins or when he registers, his $_SESSION['username'] gets the value of his username. I want to allow them access certain controllers only if they registered. But I don’t like the idea of writing this:

function __construct()
{
  session_start();
  if(empty($_SESSION['username']))
     die();

  parent::__construct();
}

in every controller I don’t want unloggined people to see. Is there any better way to do it? 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-30T18:36:15+00:00Added an answer on May 30, 2026 at 6:36 pm

    You might consider extending your base controller class (see the Codeigniter Wiki Article on extending the class) to provide a require_login function:

    class MY_Controller extends CI_Controller {
    
      protected function require_login() {
        if(empty($_SESSION['username']))
          die();
        }
      }
    

    Once you have this, you can call require_login() in the constructor of each controller you want to protect:

    function __construct() {
      $this->require_login();
    }
    

    Finally, instead of using PHP’s $_SESSION superglobal for session storage, you might consider taking advantage of the Codeigniter session library or an equivalent.

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

Sidebar

Related Questions

When a user registers with my site I want to offer them a login
I want a simple sign in app in which a user logins successfully if
I'm creating a server/client solution with custom user logins (not WindowsIdentity). I need a
I have an automation system and I would like to record user logins and
When using this user.meta.logins.$inc(); I get this error in the console: Mongoose MongooseNumber#$inc /
For instance, let's say I have a User model. Users have things like logins,
Upon user login I check their roles. If they have no roles I want
The code is for the registation table for finace app The user registers into
I'm using twitter login for my site,when user entered with his twitter login id
I have a website, with a user system. I want to integrate wordpress's user

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.