Solved

directory listing, hide files

Posted on 2007-12-01
7
1,258 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:ioustinos_sarris
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
And why B only? Whatever.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP temp path missing 4 48
Redirect all pages to one specific page 1 93
instanceof  operator in java 26 70
htaccess restrict subdomain 4 68
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 http://domain.com (http://domain.com) to http…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

13 Experts available now in Live!

Get 1:1 Help Now