SitePoint thread

How to protect files from being accessed on your server:
	  Step One
	    1. open your FTP program
	    2. navigate to the path above your root directory
	    3. create a directory called "tpihfjp"  // this_path_is_hidden_from_Joe_Public
	    4. create and save this file:  "tpihfjp/hidden_test_file.php"...
	    5. ... with the following content
	            <?php echo 'This file is in your tpihfjp directory: '__FILE__; ?> 
	
	  Step Two
	    1. change line 2 in this scipt to $RUN_TEST = TRUE;
	    2. copy this script to "show_contents_of_hidden_path.php" file on your server 
	    3. run this script file on your server
	
	  Step Three
	    1. validate results and see if it is possible to access the "tpihfjp" path.
	
	
Source file: <?php 
    $RUN_TEST 
FALSE// Change to TRUE to RUN TEST

  
error_reporting(10);    // E_ALL); // for debugging
  
ini_set('display_errors','On');  // 'On'); // for debugging
  
$title    'How to hide files on your server';

//===================================
function run_test($RUN_TEST FALSE// must be FALSE on my server
{
    if (
$RUN_TEST)
    {
        
$filename 'show_contents_of_hidden_path.php';
        
        
$document_root $_SERVER['DOCUMENT_ROOT'];
        
        
$len strlen($document_root); // 25
        
$pos strrpos($document_root"/"); // 24
        
        
$path_above_document_root substr($document_root0$pos);
        
        
$title 'Contents of your hidden path : <b>tpisfjp</b>';
        
$path  $path_above_document_root .'/tpihfjp/';
        
        echo 
'<fieldset>';
            echo 
'<legend>' .$title .'</legend>';
            
$message '<br />No we have no hidden file : '// default
            
if (file_exists($path .$filename))        
            { 
            
$message 'YES we have hidden file : ';
            include(
$path 'show_contents_of_hidden_path.php');
            }
            echo 
'<h3>'$message .$path $filename  .'</h3>';   
        echo 
'</fieldset>';
    
    }
//endif RUN_TEST
    
}//endfunc

?>
<!DOCTYPE html>
<html>
<head>
    <title><?php echo $title?></title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <link type='text/css' href='_style.css' rel='stylesheet' />
</head>
<body>
    <div>    
        <h1>
            <a href='http://www.sitepoint.com/forums/showthread.php?p=4615985#post4615985'>SitePoint thread</a>
        </h1>
        
        <?php include '_instructions.php'?>
    
        <?php 
         run_test
($RUN_TEST);
    
         
// show contents of this file
           
echo "<fieldset style='width:88%; min-width:420px; margin:2.2em auto'>";
                    echo 
'<legend>Source file:</legend>';
              
highlight_file(__FILE__);
           echo 
'</fieldset>';
           
           echo 
"<fieldset style='width:88%; min-width:420px; margin:2.2em auto'>";
                    echo 
'<legend>_style.css:</legend>';
              
highlight_file('_style.css');
           echo 
'</fieldset>';
        
?>
    </div>
    <p> 
        <?php /* simple page monitor access */ include '../_google_sitepoint.php';  ?>
    </p>    
    
</body>
</html>        
        
 
_style.css: *              {color:#000}
div,
body         {width:98%; min-width:600px; background:#fd0 none}

fieldset {width:88%; min-width:420px; margin:2.2em auto; 
                   background:#eee none; border:dotted 2px #090}
                   
a:hover  {background:#930 none; color:#fff}

p        {text-align:center}