Solved

Get server default index files with PHP

Posted on 2009-07-13
6
220 Views
Last Modified: 2013-12-13
On a server it is possible to set default index files, for instance: index.html, default.asp, index.php, etc, etc...

Is there any way to get this list of default files using PHP? Like is there some server variable I can call to get this information.

Hopefully I've explained enough, if not let me know.
0
Comment
Question by:Hube02
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:pmessana
ID: 24844923
Are you saying that if you hit URL http://www.asdfasdf.com/ you want to set the default file rendered?  If so, if you are running Apache you can set this in the httpd.conf file.

It is set with the DirectoryIndex.

eg: DirectoryIndex home.php index.php index.htm index.html

If this is not what you are talking about let me know.
0
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24844969
If you have read access to the httpd.conf file, it could be done with something like this:
$conf = 'C:\Program files\Apache Software Foundation\Apache2.2\conf\httpd.conf';

foreach(file($conf) as $line)

  if(substr(trim($line),0,14)=='DirectoryIndex')

    $defaultfiles = array_filter(explode(' ',substr(trim($line),15)));

var_dump($defaultfiles);

Open in new window

0
 
LVL 18

Author Comment

by:Hube02
ID: 24845163
@crx: This is exactly what I'm looking for, sorta... Seems I should have been more specific about my needs. What I'm looking for may not even be possible.

To explain further:

The problem is that this may be an Apache server or IIS and that there is no way for me to know beforehand where the configuration file for the server is. As an example, the path you provided is likely valid for your setup, but on my local machine the file is located at c:\WebServer\Apache2\conf\httpd.conf

And in all likelihood, depending on the environment, the configuration file itself may not be readable by PHP. I would guess that for security measures on a shared hosting environment that the host would make these files inaccessible, at least I would if I were the admin.

I was hoping for a cross platform variable or something that might store this information.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24845203
>> I was hoping for a cross platform variable or something that might store this information.

Nothing that I am aware of, sorry.
0
 
LVL 18

Author Comment

by:Hube02
ID: 24845332
Not a problem, but you did give me something to think about.

The reason that I ask is that I am working on a user/permissions module for PHP. The system will allow the admin to choose files and folders that require a login and what level of permissions are required to access the folder or file. As this is built in PHP it can only control access to php files. I was looking for some way to detect if some php file, or what the default files and order of those files are. Then I could look into each of the folders on the server and make sure that it would be a php file that is loaded by default for the given folder. This would allow me to display a warning if it is not and direct them to change the default index file on their server (or contact the host to have them do it)

I'm exploring the possibilities.
0
 
LVL 18

Author Comment

by:Hube02
ID: 24855199
I have accepted the answer given by crx because, while it may not help me, it does answer the original question and the solution may be of some help to someone else.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

896 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

15 Experts available now in Live!

Get 1:1 Help Now