Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


directory listing, hide files

Posted on 2007-12-01
Medium Priority
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


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 750 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…
Suggested Courses

722 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