Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Php's auto_prepend_file directive per directory?

Background: I've got some code that checks to see if a user has a valid session before processing the php page that I would like to set as the auto_prepend_file. However, I need to exclude the page where the user attempts to login from requiring a valid session. I would like to be able to set the auto_prepend_file value on an per directory basis.

Environment: PHP 5.2.6m Apache 2, running php as a cgi not as mod_php, on Windows (if that matters) and on a machine that I have complete control over (not a hosted environment)

Using a htaccess file is out b/c I am not using mod_php. I have not been able to alter the in php.ini to set the auto_prepend_file, the server throws an internal error. And ini_set() does not work b/c it has already loaded the session checking file before I can change the value of auto_prepend_file.

I do not see a way to set auto_prepend_file on a per directory basis if you are not using mod_php/htaccess. Am I missing something?

like image 760
CLJ Avatar asked Nov 22 '10 17:11

CLJ


2 Answers

You mention you can't use .htaccess files but can you make modifications to httpd.conf and do something like this:

<Directory "c:/wamp/www/dev/">
    Php_value auto_prepend_file c:/wamp/www/dev/prepend.php
</Directory>

EDIT - just realised this doesnt work when running as CGI. I think though that one thing that will work is if you create a copy of your php.ini file, place it in the directory, and put your prepend directive in there like:

auto_prepend_file = c:/wamp/www/dev/prepend.php
like image 143
robjmills Avatar answered Nov 08 '22 14:11

robjmills


Use .user.ini files.

http://php.net/manual/en/configuration.file.per-user.php

like image 20
Matthew Avatar answered Nov 08 '22 13:11

Matthew