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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:56:44+00:00 2026-05-16T20:56:44+00:00

I’ve read quite a few posts that are very similar to the question I’m

  • 0

I’ve read quite a few posts that are very similar to the question I’m about to ask, but I just wanted to be sure that there wasn’t a more sophisticated way to do this. Any feedback is greatly appreciated.

I want to create a mechanism to check whether or not a logged-in user has access to the php script that is currently being called. If so, the script will continue on; if not, the script just fails out using something like die('you have no access').

I came up with two ways of accomplishing this:

(please assume my session stuff is coded/working fine – i.e. I call session_start(), set up the session vars properly and etc)

  1. Define a global variable first, then check the global variable in a required header file. For example:

    Content of current_executing_script.php:

    // the role the logged in user must have to continue on   
    $roleNeedToAccessThisFile = 'r';
    require 'checkRole.php''
    

    Content of checkRole.php:

    if ($_SESSION['user_role'] != $roleNeedToAccessThisFile) die('no access for you');
    
  2. Define a function within the header file and call the function immediately after including/requiring it:

    Content of checkRole.php:

    function checkRole($roleTheUserNeedsToAccessTheFile) {
        return ($_SESSION['user_role'] == $roleTheUserNeedsToAccessTheFile);
    }

    Content of current_executing_script.php:

    require 'checkRole.php';
    checkRole('r') or die('no access for you');

I’m wondering if there is a way to basically just pass a parameter to checkRole.php as part of the include or require construct?

Thanks in advance.

  • 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-16T20:56:45+00:00Added an answer on May 16, 2026 at 8:56 pm

    There isn’t a way to pass parameters to include or require.

    However the code that is included joins the program flow at the point where you include it, so it will inherit any variables that are in scope. So for example if you set $myflag=true immediately before the include, your included code will be able to check what $myflag is set to.

    That said, I wouldn’t suggest using that technique. Far better for your include file to contain functions (or a class) rather than code that gets run straight off. If you’ve included a file containing functions then you can call your functions with whatever parameters you want at any point in your program. It’s much more flexible, and generally a better programming technique.

    Hope that helps.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the

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.