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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:59:11+00:00 2026-06-15T17:59:11+00:00

The users when they sign up are given a default ‘member_type’ as User. I’m

  • 0

The users when they sign up are given a default ‘member_type’ as “User”. I’m trying to restrict access to certain pages from “Users” and unauthenticated visitors using $_SERVER[‘SCRIPT_NAME’] using a function stored in the header.php.

The concept is sound (I believe) but I really need some fresh eyes to help me solve the logic.

Here is the function in the header:

$basicAuth = array("member.php", "order.php", "logout.php");
    $adminonly = array("admin.php", "v_feedback.php", "user.php", "v_content.php", "product.php");


    restrictAccess($basicAuth, $adminonly);

And here is the function in its entirety:

function restrictAccess($basicAuth, $adminonly){
$error = "You do not have the authentication privileges to access this area, go <a href=\"index.php\" alt=\"Home\">home</a>.";

    if (isset($_SESSION['type'])){
        $auth = "Basic";

        if($_SESSION['type']=="Admin"){
            $auth = "Admin";
        }
    } else {
        $auth = "None";
    }

    //For testing purposes
    echo $auth;



if ($auth == "None"){
    if(($_SERVER['SCRIPT_NAME']==$basicAuth)||($_SERVER['SCRIPT_NAME']==$adminonly)){
        echo $error;
        exit();
    }
}elseif($auth =="Basic"){
    if(($_SERVER['SCRIPT_NAME'])==$adminonly){
        echo $error;
        exit();
    }
}

}

I have a feeling that it something to do with the logic behind the way I’ve structured it which is to fault.

Thank you.

  • 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-15T17:59:12+00:00Added an answer on June 15, 2026 at 5:59 pm

    if($_SERVER['SCRIPT_NAME']==$basicAuth) is completely wrong.
    You can not compare array and a string.
    if(array_search($_SERVER['SCRIPT_NAME'],$basicAuth) !== FALSE) would serve, but You better use keys instead of values, and then if(array_key_exists($_SERVER['SCRIPT_NAME'],$basicAuth)).
    And, by the way, isn’t it simplier to include “basicAuthNeeded.php” into some scripts and “adminAuthNeeded.php” into other instead of Your method?
    Or else use more complex but more flexible method (define some roles, define resources and use some checkPermissions($role, $resource))?

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

Sidebar

Related Questions

I'm trying to save the site that a user came from when they sign
I want to sign users in automatically after they create an account. My application
I'm trying to send push notifications to users when they are at a specific
I'm currently running a web-app that will send emails to users when they sign-up,
I need to get access to my user's information when they are offline and
I'm trying to login users to websites automatically, given their username and password. To
Scenario: User gives you an email address. Before they can sign up for services,
What should do to setup a sub-domain for the users when they sign-up into
I have a database of users where they can send messages to other users
How do i read in char type by users if they are a- ,

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.