Jump to content

Preventing Direct Access of a subfolder


cooldude832

Recommended Posts

I am trying a new schematic for laying out my site so I can take it done and up very quickly by adjusting a single line.  So each actual document that I want the players to view are

<?php
$page = "index";
$title = "Home Page";
require_once('constants.php');
require_once(SCRIPTS.'shell.php');
?>

 

That works great and the $page var sets what the name of the source code is for the content area and the shell file is the skeleton outline. 

 

Any way in the file of shell it has a line of

<div id="content">
<?php require(SUB_FOLDER.$page.EXT);?>
</div>

I want to prevent people from directly accessing the files in the SUB_FOLDER location, as it is just raw source code that shouldn't be viewed outside the skeleton, also if the site is down I want to prevent people from getting around this and going into that folder and viewing the site/logging in.

 

So my question comes down to this, should I put a bit of coding in the top of each source page that says

<?php 
$page_url = BASE.SUB_FOLDER."page name".EXT;
//this equals mydomain.com/subfolder/page_name.php  
if($_SERVER['self''] == $page_url){
exit(header("Location: mydomain.com"));
}
?>

Or can I do this with chmod/.htaccess to prevent direct access to this folder?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.