Now, you need to leave an interface for users to modify similar configuration files through the web interface, the main way is to call the Linux shell scrip{filter}t from PHP, so now paste a linux shell that can modify this configuration file.
First, the configuration file is formatted as follows:
Examples are as follows, config.ini:
The configuration file contains 3 units, representing 3 major aspects: database, business, offline; Each unit has its own field name and field value.
The blog mentioned above can read such a configuration file, and for now we are going to modify this configuration file through the Linux shell.
We designed a program called modify_config_file and modified it using a format like ./modify_config_file unit1-field1=changed_value1 unit2-field1=changed_value2 (parameters can be added as needed).
It is not difficult to achieve the ability to modify the configuration file, 20-30 lines can solve the problem. However, based on the principle of "all inputs are harmful", it is necessary to add various fault tolerance processing to the shell, if the user parameter input is wrong, to be able to remind the user in time and locate the problem, the following is based on such an original intention of the shell, of course, the name is modify_config_file:
The user modifies the configuration with the following command:
The output is as follows:
Among them, the first line indicates that the line number interval where the BUSINESS unit is located, pay attention to the opening interval; The second line represents all match to field line numbers, as there may be multiple units of the same field; The third line indicates the field line number that finally falls into the unit interval; The fourth line represents the result of the revision of the row.
In addition, it is very likely that the user input does not conform to the format, and the following errors will be reported and targeted:
If you want to apply it to other configuration files, you need to modify the path and file name of the configuration file in the script:
|