PDA

View Full Version : Hiding the display of index.php from Dir Files Listing


iota
03-10-2006, 09:03 AM
Hi Php Masters,

How do I hide the display of index.php from Dir Files Listing ?

The code in the index.php is



<?php

if ($handle = opendir('.')) {
echo "<ol>" ;
while (false !== ($file = readdir($handle))) {

if ($file != "." && $file != "..") {

echo "<b><li><a href='$file'>$file</a> </li></b>\n";


}

}
echo "</ol>";
$handle = fopen($file, "rb");
$contents = fread($handle, filesize($file));
fclose($handle);
closedir($handle);
}
?>


Thank you extremely much.

BaDgEr
03-10-2006, 10:25 AM
I expect it may be in your webservers configuration settings.

degsy
03-10-2006, 02:01 PM
Setup an array of hidden files to check against


$hidden = array(
'.',
'..',
'index.php'
);

if ($handle = opendir('.')) {
echo "<ol>" ;
while (false !== ($file = readdir($handle))) {

if (!in_array($file, $hidden)) {

lansing
03-10-2006, 04:32 PM
Is this coding above were on URL would look like this http://www.domainname.com/?a=contactus

& not look like this: http://www.domainname.com/contactus.php

I have seen this on many sites, but I have no clue on how to do this.

goughy000
03-10-2006, 09:31 PM
Is this coding above were on URL would look like this http://www.domainname.com/?a=contactus

& not look like this: http://www.domainname.com/contactus.php

I have seen this on many sites, but I have no clue on how to do this.

1) You should start your own topic
2) No its not
3) this question has been answered many times before

page.php?a=1

<?php
$variableone = $_GET['a'];

// Prints out "1"...
echo $variableone;
?>