Having a PHP site points to a different path than the one in the code.

I am using a PHP site on Windows using Wampserver. There is a line with a hard code throughout the site, for example:

$settings = parse_ini_file("/usr/local/apache2/myconfigs/settings.ini", true); 

I know that this is bad practice, but it is not in my power.

When the site is working, is there any possible way I can trick the site into pointing to C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini whenever the code looks for /usr/local/apache2/myconfigs/settings.ini in the parse_ini_file function?

+5
source share
5 answers

This is a bit hacky, but I think this is what you are looking for, so here you need to override the parse_ini_file function and ignore the invalid path ( "/usr/local/apache2/myconfigs/settings.ini" ) and use your correct file instead.

This seems simple, but a bit complicated, since your new function must somehow call the parse_ini_file function, so you need to rename it first and then redefine it .

For this you will need the runkit PHP extension , see runkit_function_redefine and runkit_function_rename for help.

Unconfirmed, but should work, the code should be something around these lines:

 runkit_function_rename('parse_ini_file','original_parse_ini_file'); runkit_function_redefine('parse_ini_file', function() { original_parse_ini_file("C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini", true); }); 

Make sure the above code runs at the beginning of your script application, and any call to parse_ini_file should use your file instead of hard-coded.

If the application does not have a single entry point where you can place the code above, you can put it in a separate script and make PHP load before running any script using the auto_prepend_file parameter in settings.ini , also make sure that runkit.internal_override set to On , since parse_ini_file not a user-defined function.

+1
source
 $settings = parse_ini_file(APACHE_INI_PATH, true); // $settings = parse_ini_file("/usr/local/apache2/myconfigs/settings.ini", true); 
+3
source

Hi please check this out

 runkit_function_rename('parse_ini_file','o_parse_ini_file'); runkit_function_redefine('parse_ini_file', function($p1,$p2) use($someCondition) { if($someCondition) o_parse_ini_file("C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini", true); else o_parse_ini_file($p1,$p2); }); 

he can come back

Function call undefined runkit_function_rename ()

to fix this error please read here

or here

+1
source

If you do not want to search and replace as suggested by @cddoma, I suggest you create the directory / usr / local / apache2 / myconfigs / on your Windows computer and copy the settings.ini file from C: \ wamp64 \ bin \ apache \ apache2 .4.27 \ myconfigs \ settings.ini to this directory.

Open a windows command prompt and enter the following

mkdir C:\usr\local\apache2\myconfigs\

copy C:\wamp64\bin\apache\apache2.4.27\myconfigs\settings.ini C:\usr\local\apache2\myconfigs\

0
source

You can do this using Symbolic Link in Windows

0
source

Source: https://habr.com/ru/post/1275601/


All Articles