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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:41:04+00:00 2026-06-08T01:41:04+00:00

I’ve got a make-do page authenticator which defines what usergroups are allowed to access

  • 0

I’ve got a “make-do” page authenticator which defines what usergroups are allowed to access that page, however, some of my scripts allow the user to pass if that page is, say, his user edit page but not touch any other users edit page. For that, I disabled access to the usergroups except if you’re an admin or the user edit page you are currently on is your own.

I tried to create a function to do this, but the allowOnly usergroups function deals out the punishment without checking to see if the other function is defined elsewhere on the page.

Here’s the “make-do” functions and an example of how I’d like them to work:

    public function allowOnly($officer, $administrator, $superuser)
{
    $authority = 0;
    if ($officer == true && $this->session->isOfficer()) {
        $authority++;
    }
    elseif ($administrator == true & $this->session->isAdmin()) {
        $authority++;
    }
    elseif ($superuser == true & $this->session->isSuperuser()) {
        $authority++;
    }
    if ($authority != 0) {
        return true;
    }
    else {
        header("Location: ../incorrectRights.php");
        exit;
    }
}
function allowCurrentUser()
{
    global $authority;
    $authority++;
}

This changes the users location if they’re not any of the allowed usergroups, but since that code is executed before “allowCurrentUser”, it changes the location before the function gets the chance to allow the user through.

I’d like it to work like this:

<?php
     include("functions.php");
     $functions->allowOnly(false, false, true);
     if($session->username == $allowedUserName) {
          $functions->allowCurrentUser();
      }

I’m sorry if I’m not descriptive enough, or my code lacks efficiency, heck, even if I’ve missed a built-in php function which does this for me!

  • 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-08T01:41:06+00:00Added an answer on June 8, 2026 at 1:41 am

    you should check out PHP’s function_exists(), this will tell you wether or not the function already exist.

    you have some error in your code too.

    $administrator == true & $this->session->isAdmin()
    

    should be

    $administrator == true && $this->session->isAdmin()
    

    as you have used only single & whereas it should be &&

    and also change

    $superuser == true & $this->session->isSuperuser()
    

    to

    $superuser == true && $this->session->isSuperuser()
    

    after reading your code, i realized you are using $authority variable to hold the value and to check wether to authorize user or not. and plus you are using global. i would never have done that way, instead i would declare $authority as class property below is the example of how you could do it.

    class functions 
    {
        //declare class propert and set default value to 0
        protected $_authority = 0;
    
        public function allowOnly($officer, $administrator, $superuser)
        {
            if ($officer == true && $this->session->isOfficer()) {
                $this->_authority++;
            }
            elseif ($administrator == true && $this->session->isAdmin()) {
                $this->_authority++;
            }
            elseif ($superuser == true && $this->session->isSuperuser()) {
                $this->_authority++;
            }
            if ($this->_authority != 0) {
                return true;
            }
            else {
                header("Location: ../incorrectRights.php");
                exit;
            }
        }
    
        public function allowCurrentUser()
        {
            $this->_authority++;
            return $this->_authority;
        }
    }
    

    UPDATE:

    instead of redirecting the page why not return false and redirect during function call, you can do it this way.

    class functions 
    {
        //declare class propert and set default value to 0
        protected $_authority = 0;
    
        public function allowOnly($officer, $administrator, $superuser)
        {
            if ($officer == true && $this->session->isOfficer()) {
                $this->_authority++;
            }
            elseif ($administrator == true && $this->session->isAdmin()) {
                $this->_authority++;
            }
            elseif ($superuser == true && $this->session->isSuperuser()) {
                $this->_authority++;
            }
    
            return ($this->_authority != 0) ? true : false;
        }
    
        public function allowCurrentUser()
        {
            $this->_authority++;
            return $this->_authority;
        }
    }
    

    and while in function call.

    include("functions.php");
    if($functions->allowOnly(false, false, true)) {
        //person is allowed access
    } 
    //else allow current user
    elseif($session->username == $allowedUserName) {
        $functions->allowCurrentUser();
    } 
    else {
        //redirect here
        header("Location: ../incorrectRights.php");
        exit;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.