Solved

directory listing, hide files

Posted on 2007-12-01
7
1,262 Views
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?
0
Comment
Question by:ioustinos_sarris
[X]
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
7 Comments
 
LVL 21

Expert Comment

by:nizsmo
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).
0
 

Author Comment

by:ioustinos_sarris
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.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20388845
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
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

by:ioustinos_sarris
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?
0
 
LVL 21

Expert Comment

by:nizsmo
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 :)
0
 
LVL 43

Accepted Solution

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

IndexIgnore a*.php b*.php

http://httpd.apache.org/docs/2.0/mod/mod_autoindex.html#indexignore
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 20485472
And why B only? Whatever.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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