logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.



reading Apache settings with PHP

 
Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner



View previous topic :: View next topic  
Author Message
japo



Joined: 09 Jul 2009
Posts: 3

PostPosted: Thu 09 Jul '09 15:45    Post subject: reading Apache settings with PHP Reply with quote

Hi all,

i have some apache settings ^^ some are placed in the virtual host settings, some are set in .htaccess files.

E.g.
* RewriteEngine on
* XSendFile off
* Foo bar

Now i am wondering if it is possible to get the resulting settings within a php script WITHOUT parsing the configs. For Example, if XSendFile is set to on, i would like to use this module, otherwise a php method should take care of file delivering.

Do you have any suggestions?

Kind Regards,
japo
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Fri 10 Jul '09 9:43    Post subject: Reply with quote

I'm not realy sure what you want. But maybe you want a url that acts like a file?

Code:

<Files "foo">
SetHandler application/x-httpd-php
</Files>


Code:

<?php
$arguments = explode( ‘/’,
   $_SERVER[‘PATH_INFO’] );
print_r($arguments);
?>


So you can call http://example.com/foo/bar

and in $arguments['0'] is bar


if it is not what you want please tell us more.
Back to top
japo



Joined: 09 Jul 2009
Posts: 3

PostPosted: Fri 10 Jul '09 11:17    Post subject: Reply with quote

hello,

thank you for your reply, but this is not my problem. I'll try to explain it again with a concrete example.

E.g.
I have mod_xsendfile installed (This module is able to deliver files without having a php script running, after a special header information was send which let apache directly deliver the file). One of my public accessible subfolders contains a .htaccess file. This file contains:
* a mod_rewrite rule to point all *.(bmp|png|...) requests to a access check php script
* two settings for x-sendfile to enable the x-sendfile module for the public subfolder. (XSendFile On; XSendFileAllowAbove On;)

Now, the question is: is there any way to get the "XSendFile" value (or any other value of a .htaccess setting) within a php script?

The php script could look like

Code:
if (in_array('mod_xsendfile', apache_get_modules())
{
  // mod_xsendfile is loaded, but that does not mean, that the settings allow to use it
  // maybe XSendFile is set to off
  if (GET_APACHESETTING('XSendFile') == 'on') // <-- this is what i am looking for
  {
     //send file with x-sendfile header
  }
}
else
{
  // send file with fpassthroug or something like that
}


In the case of x-sendfile, the check for XSendFile == on is a security related check. If x-sendifle is loaded but not active for the current http-request, filesysteminformation might be sent to the client in the http header fields. So it is important (in my case) to check if the module realy will be used for delivering.

I hope, my question gets clearer now. If not, please ask Smile

kind regards,
japo
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6255
Location: Germany, Next to Hamburg

PostPosted: Fri 10 Jul '09 21:48    Post subject: Reply with quote

Hm ok.
I think you can do it in a workaround. Since you edit hte .htaccess file by hand.

My I idea:
You can set an envirioment variable in .htaccess.
e.g.
Code:

setenv XSendFile on


than in php code

Code:

if (in_array('mod_xsendfile', apache_get_modules())
{
  // mod_xsendfile is loaded, but that does not mean, that the settings allow to use it
  // maybe XSendFile is set to off
  if ($_ENV['XSendFile'] == 'on') // <-- this is what i am looking for

  {
     //send file with x-sendfile header
  }
}
else
{
  // send file with fpassthroug or something like that
}


maybe you have to use apache_getenv instead of $_ENV. I haven't tested it nor tried it.

Hope this helps. If not tell us more Wink
Back to top
japo



Joined: 09 Jul 2009
Posts: 3

PostPosted: Fri 10 Jul '09 22:43    Post subject: Reply with quote

hmmmmmmmmmmmmmm xD

i really would like to read out the value directly Wink but if there is no way to do that, your suggegtion might be an alternative.

i am still subscribed to this thread, if you or someone else finds or knows a nicer solution please let me know..

regards,
japo
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2123
Location: Sun Diego, USA

PostPosted: Fri 10 Jul '09 23:25    Post subject: Reply with quote

The only public api into Apache for a php or any script to the best of my knowledge is the environment. Wherever you set XSendFile to on, also set the env var.

This will be the easiest. If such an api does indeed exist, I would imagine it's going to be in the php module itself which does have access to the current Apache configuration. Closest I see tho is just a list of loaded modules (apache_get_modules).
Back to top


Post new topic   Reply to topic    Apache Forum Index -> Coding & Scripting Corner
Page 1 of 1