directory listing, hide files

Posted on 2007-12-01
Last Modified: 2012-06-27
hi there,
i have a folder that users can see from their browser with the typical directory listing. however i have some php files which i would like to keep hidden. is there a way to do that?
Question by:ioustinos_sarris
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 21

Expert Comment

ID: 20388801
Yes, you can write your own directory listing script, and then you can filter and choose to hide the PHP script files quite easily (by not showing them).

Author Comment

ID: 20388808
i am using the default apache directory listing script, meaning that i just dont have an index file in the directory. i wouldn't bother writing my own script.
LVL 21

Expert Comment

ID: 20388845

It is easier than you think. Try and save the below simple script as index.php and put it in the directory you want to hide the php files. Note that my script is hiding both PHP and HTML files at the moment, you can just hide the PHP files by editing the extensions not showing line.
//define the path as relative
$path = "./";
//extensions NOT showing
$regpattern = '.php$|.html$';
//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "Directory Listing of $path<br/>";
$filelist = Array();
//running the while loop
while ($file = readdir($dir_handle))
		$filelist[] = $file;
foreach ($filelist as $file)
	echo "<a href='$file'>$file</a><br/>";
//closing the directory

Open in new window

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 20388885
really helpful thanks but my client for his own reasons really wants the default directory listing. he likes the way it shows. i could work a bit on it though to make it look the same.

isn't there a way to hide it by changing some permissions or attributes of the file on the apache server?
LVL 21

Expert Comment

ID: 20388888
you can try and make it a "hidden" file (if you are in windows) but not that I know of, since I use the script above if I want to hide anything specific. Yes you can edit the script accordingly, probably get it to show very similar to the default one :)
LVL 43

Accepted Solution

ravenpl earned 250 total points
ID: 20390475
Into the .htaccess

IndexIgnore a*.php b*.php
LVL 43

Expert Comment

ID: 20485472
And why B only? Whatever.

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting ( to http…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question