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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:49:40+00:00 2026-06-09T11:49:40+00:00

i want to give access only to the authorized users so i wrote the

  • 0

i want to give access only to the authorized users
so i wrote the authentication code in the construct method
here is my code

class cp extends CI_Controller {

    public function __construct(){
        parent::__construct();
        $this->this_mustbe_admin();
    }

    public function this_mustbe_admin()
    {

        $this->load->model('m_cp');
        $md = $this->m_cp->is_admin();
        if($md)
         return $md;
        else
        {
            redirect(base_url().'cp/login/');
        }

    }

    function login()
    {   
             $this->load->view('admin/login');

    }

but i get error

The page isn't redirecting properly

if i remove this_mustbe_admin method from construct and put it on the other controllers it works fine

function do_stuff(){

   $this->this_mustbe_admin();
   // do stuff 

}

but this way i have to write it in each and every one of my methods

  • 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-06-09T11:49:42+00:00Added an answer on June 9, 2026 at 11:49 am

    You doing circular redirection. An imaginary stack trace:

    1. http request to /cp/
    2. __construct()
    3. this->this_mustbe_admin() -> redirect to /cp/login
    4. http request to /cp/login
    5. __construct()
    6. this->this_mustbe_admin() -> GOTO 3.

    You will have to check what method you are trying to execute in your __construct before doing the redirection generating command.

    if (!$this->router->method != 'login') {
        $this->this_mustbe_admin();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to give access to protected properties to another class. I have been
We have a website site.com and want to give faster access to that site
I want to give a user access to a stored procedure, but not to
I want to give permission to a user to access my database using work
I want to access the children with skos:Concept. getChildren(skos:Concept) and getChildren(Concept) both give me
I want to give the name of MainWindow.xib file in plist file through code,
I want to give access to some of the resources in my web application
If I want only administrator to access the action called ManagerUser, I know I
I want to give permissions only to specificated rows in mysql. table: messages cols:
I want to give access to certain data, in various databases on a single

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.