Solved

directory listing, hide files

Posted on 2007-12-01
7
1,263 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

Question has a verified solution.

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

Suggested Solutions

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
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). #…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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