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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:46:50+00:00 2026-05-29T22:46:50+00:00

I am writing an admin check to make sure that the email that is

  • 0

I am writing an admin check to make sure that the email that is logging into the admin area is:

  • An admin user
  • Is active

I have so far written the following code:

Controller:

$this->form_validation->set_rules('userName','userName', 'required|trim|max_length[99]|callback_admin_check|xss_clean');

function _admin_check($adminUsername, $adminEmail)
            {
                if($this->users_model->admin_check($adminUsername) || $this->users_model->admin_check($adminEmail))
                {
                    $this->form_validation->set_message('admin_check', 'Sorry you have an %s error!');
                    return FALSE;
                }else{
                    return TRUE;
                }

What I am confused about here is that I would like it to accept both the admin username or email address if the userGroup == admin or if the account is userActive == yes but I am unsure how I would construct the model to or what data to send through to the model.

Update -> Joe:

Joe,

Just a couple of questions:

  • Do I still set my validation error messages where it return false?
  • Is there anyway that I could check that the account is an admin account and is active?
  • Is the Model OK?

Controller:

function _admin_check($adminUsername = null, $adminEmail = null)
    {
        $adminUser = $this->user_model->admin_check($adminUsername,$adminEmail);

        //if the UN || PW are not correct

        if(! $adminUser)
        {
            $this->session->set_flashdata('login_error', TRUE); // Does not bother adding incorrect data into the session for the Admin Login
            $this->form_validation->set_message('admin_check', 'Sorry you have a %s error!');
            return FALSE;
        }else{
            //Set the session data
            $this->session->set_userdata('logged_in', TRUE);
            $this->session->set_userdata('userId',$adminUser->id);
            $this->session->set_userdata('userFirstName',$adminUser->userFirstName);
            $this->session->set_userdata('userLastName',$adminUser->userLastName);
            $this->session->set_userdata('userEmail',$adminUser->userEmail);
            $this->session->set_userdata('userGroup',$adminUser->userGroup);
            $this->session->set_userdata('userActive',$adminUser->userActive);
            return TRUE;
        }

Model:

            function admin_check($adminUsername, $adminEmail)
    {
            if(is_null($adminUsername && is_null($adminEmail)))
            {
                return FALSE;
            }

            if(is_null($adminUsername))
            {
                $login_field = 'userEmail';
                $login_name = '$adminEmail';
            }else{
                $login_field = 'userName';
                $login_name = '$adminUsername'
            }

            $this->db->select($login_field,$login_name);
            $this->db->from('users');
            $this->db->where('userName', $adminUsername , 'userEmail' , $adminEmail );
            $query = $this->db-get();

            if($query->num_rows() > 0)
            {
                return TRUE;
            }else{
                return FALSE;
            }
        }
  • 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-29T22:46:52+00:00Added an answer on May 29, 2026 at 10:46 pm

    Set the defaults for both parameters to null: function _admin_check($adminUsername = null, $adminEmail = null)

    Then at the top of the method in the model, add this:

    function admin_check($adminUsername = null, $adminEmail = null)
    {
        if (is_null($adminUsername) && is_null($adminEmail))
        {
            return false;
        }
    
        if (is_null($adminUsername))
        {
            $login_field = 'email'; // field in the table
            $login_name = $adminEmail; // value of the field
        }
        else
        {
            $login_field = 'username';
            $login_name = $adminUsername;
        }
    
        // Your SQL here, using $login_field and $login_name
    

    To call with the username, call like this:

    $this->users_model->admin_check($adminUsername);
    $this->users_model->admin_check($adminUsername, null); // or this
    

    And for the email

    $this->users_model->admin_check(null, $adminEmail);
    

    To call it in one:

    $this->users_model->admin_check($adminUsername, $adminEmail);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a quick little add-in for Outlook that will check my email every
I have written an ASP.NET web page with C# behind that runs an existing
I am writing a debug/admin node server that allows users to execute a long-running
We are writing a user management module where the admin can change passwords for
Is that possible? I'm writing a web-admin interface for a network-system. I need to
I'm writing a custom admin stuff and need to get all registered models in
I am writing a VSTO addin for Word 2007. When the user selects File->New,
Writing htaccess that allows me to remove index.php from the URL can confuse search
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing documentation in html requires some code examples. What to do with characters that

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.