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

The Archive Base Latest Questions

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

I am utilizing a custom MY_Controller to authenticate users on my Codeigniter website. I

  • 0

I am utilizing a custom MY_Controller to authenticate users on my Codeigniter website.

I utilize $this->load->vars($data); such that I can access the users information in views.

My first question is, does $this->load->vars($data); allow access in models, and if so how – i couldn’t find any information. If not, how can I get my logged in users username to my models without having to pass it through a controller every time?

Secondly… if the user is not logged in, I redirect them redirect(base_url() . 'account/login');

This works great, except because my account controller also extends MY_Controller, it gets stuck in an infinite redirect loop. I can just not extend the custom controller for this page, but I see no reason why a logged in user should not still be able to look at the login page.. any ideas?

Finally.. if a user is logged in, $user['username'] is defined in my views.
If a user is not logged in, it is not defined.

As such if i have if($user['username']!=''){ within my code, when a user IS logged in, all is fine and the code executes, however when no user is logged in errors pop up as regards an undefined variable being used in an if statement…

Codeigniter being difficult..

What is the work around here?

Many 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-24T11:36:14+00:00Added an answer on May 24, 2026 at 11:36 am

    I agree with Chris about storing user details in the session.

    To check if a user is logged in you could write a gatekeeper function and place it in the controllers construct to protect controllers (and therefore the views).
    Something like;

    function gatekeeper()
    {
        if (!isset($this->session->item('username')) || !$this->session->item('username'))
        {
            redirect('/account/login);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way (utilizing Reflection I hope) that I can make an instantiated
I've got a ASP.NET website that is utilizing many aspects of the Enterprise Library
I'm writing a system utilizing jQuery Validation that pulls in custom rules, messages via
We are utilizing the XML data type in Microsoft SQL Server 2005 for a
I am utilizing the javax.scripting with Rhino in this project. I have a Java
I'm am utilizing a formset to enable users subscribe to multiple feeds. I require
When I navigate on a website utilizing MasterPages, does the application know what page
I have a custom class library that performs validation. I want to open up
When utilizing a UI abstraction, then the data you're displaying is protected from implementation
I'm relatively new to utilizing web services. I'm trying to create one that will

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.