How to set Php's auto_prepend_file directive per directory?

26,007

Solution 1

Use .user.ini files.

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

Solution 2

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
Share:
26,007
CLJ
Author by

CLJ

Updated on July 05, 2022

Comments

  • CLJ
    CLJ almost 2 years

    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?

  • CLJ
    CLJ over 13 years
    That did not work for me on my system...should it be working?
  • Matthew
    Matthew over 13 years
    It's worth the upgrade if you have control over that. Otherwise, you'll need to edit the main Apache configuration files.
  • CLJ
    CLJ over 13 years
    What could be preventing this from working on my machine? When I put that line it I get this error message when restarting apache: Invalid command 'Php_value', perhaps misspelled or defined by a module not included in the server configuration
  • CLJ
    CLJ over 13 years
    Thank you for updating your response.
  • Nikunj Sardhara
    Nikunj Sardhara about 7 years
    This is just a link answer thus it should be downvoted or removed completely, It doesn't matter if it helps the person who asked the question, because some highly knowledgeable, disciplined and a reputation hogger told me in comment so. I mean come on, you should provide the code snippet, may be the code of whole file, or may be you should complete whole project, or you should earn money for him for whole life for the person who asked the question. Yes that's should be done.