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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:38:32+00:00 2026-06-16T19:38:32+00:00

For my project I have created a folder named DBAccess which holds all database

  • 0

For my project I have created a folder named DBAccess which holds all database related PHP files having PHP classes,constants functions etc.In the outside of the folder I have created a php file named DBAccess.php.
following is my directory structur in short

Project1
  |_DBAccess
  |       |_functions.php
  |       |_class.php
  |       |_constants.php         
  |_DBAccess.php
  |_index.php
  |_aboutus.php  
    .......

Now i wish to restrict any pages in the root directory to use the contents of the DBAccess folder except the DBAccess.php file.Is it posssible in PHP using .htaccess or something else?

  • 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-16T19:38:33+00:00Added an answer on June 16, 2026 at 7:38 pm

    You could do something like this:

    DebugAccess/foo.php

    <?php
    $trace = debug_backtrace();
    
    if (isset($trace[0])) {
      $dir =  basename(dirname($trace[0]['file']));
      $file = basename($trace[0]['file']);
      if ($file != 'DBAccess.php' && $dir != 'DBAccess') {
        throw new Exception("Nice try butthead");
      }
    }
    
    echo "Access Granted\n";
    

    DBAccess.php

    <?php
    include_once("DBAccess/foo.php");
    

    NoDBAccess.php

    <?php
    include_once("DBAccess/foo.php");
    

    > php DBAccess.php 
    Access Granted
    
    > php NoDBAccess.php 
    
    Fatal error: Uncaught exception 'Exception' with message 'Nice try butthead' in /Users/seanberry/so/DBAccess/foo.php:7
    Stack trace:
    #0 /Users/seanberry/so/NoDBAccess.php(3): include_once()
    #1 {main}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a project MyProject.Data, I have a folder named mappings with all mapping in.
I have a C# project (Windows Console Application). I have created a folder named
I have created a group folder in my Xcode project named USER_PHOTO Then I
I have created a new folder in my project, aptly named 'images'. I have
I have created folders in my project named Classes, Forms, and Models. Let's say
I noticed that I had a project named RemoteSystemTempFiles which I never have created.
For a new project I have created a local folder tree with empty Visual
I have created one library project in iphone and my images folder is present
should i after i have created a svn repo, import one project folder into
I have created a project that uses scala that has some abstract classes definitions

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.