• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1269
  • Last Modified:

directory listing, hide files

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?
0
ioustinos_sarris
Asked:
ioustinos_sarris
  • 3
  • 2
  • 2
1 Solution
 
nizsmoDeveloperCommented:
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).
0
 
ioustinos_sarrisAuthor Commented:
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.
0
 
nizsmoDeveloperCommented:
ioustinos_sarris,

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.
<?php
 
//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))
{
	if(!ereg($regpattern,$file))
	{
		$filelist[] = $file;
	}
}
 
sort($filelist);
 
foreach ($filelist as $file)
{
	echo "<a href='$file'>$file</a><br/>";
}
 
//closing the directory
closedir($dir_handle);
 
?>

Open in new window

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
ioustinos_sarrisAuthor Commented:
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?
0
 
nizsmoDeveloperCommented:
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 :)
0
 
ravenplCommented:
Into the .htaccess

IndexIgnore a*.php b*.php

http://httpd.apache.org/docs/2.0/mod/mod_autoindex.html#indexignore
0
 
ravenplCommented:
And why B only? Whatever.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now