Solved

directory listing, hide files

Posted on 2007-12-01
7
1,259 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
  • 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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). #…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now