What is web config file in php

What is web config file in php

The configuration file ( php.ini ) is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.

  • SAPI module specific location ( PHPIniDir directive in Apache 2, -c command line option in CGI and CLI)
  • The PHPRC environment variable.
  • The location of the php.ini file can be set for different versions of PHP. The root of the registry keys depends on 32- or 64-bitness of the installed OS and PHP. For 32-bit PHP on a 32-bit OS or a 64-bit PHP on a 64-bit OS use [(HKEY_LOCAL_MACHINE\SOFTWARE\PHP] for 32-bit version of PHP on a 64-bit OS use [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP] ] instead. For same bitness installation the following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z] , [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x] , where x, y and z mean the PHP major, minor and release versions. For 32 bit versions of PHP on a 64 bit OS the following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y.z] , [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x] , where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
  • [HKEY_LOCAL_MACHINE\SOFTWARE\PHP] or [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP] , value of IniFilePath (Windows only).
  • Current working directory (except CLI).
  • The web server’s directory (for SAPI modules), or directory of PHP (otherwise in Windows).
  • Windows directory ( C:\windows or C:\winnt ) (for Windows), or —with-config-file-path compile time option.
Читайте также:  Css apply to all text

If php-SAPI.ini exists (where SAPI is the SAPI in use, so, for example, php-cli.ini or php-apache.ini ), it is used instead of php.ini . The SAPI name can be determined with php_sapi_name() .

Note:

The Apache web server changes the directory to root at startup, causing PHP to attempt to read php.ini from the root filesystem if it exists.

Using environment variables can be used in php.ini as shown below.

Example #1 php.ini Environment Variables

; PHP_MEMORY_LIMIT is taken from environment memory_limit = $

The php.ini directives handled by extensions are documented on the respective pages of the extensions themselves. A list of the core directives is available in the appendix. Not all PHP directives are necessarily documented in this manual: for a complete list of directives available in your PHP version, please read your well commented php.ini file. Alternatively, you may find » the latest php.ini from Git helpful too.

Example #2 php.ini example

; any text on a line after an unquoted semicolon (;) is ignored [php] ; section markers (text within square brackets) are also ignored ; Boolean values can be set to either: ; true, on, yes ; or false, off, no, none register_globals = off track_errors = yes ; you can enclose strings in double-quotes include_path = ".:/usr/local/lib/php" ; backslashes are treated the same as any other character include_path = ".;c:\php\lib"

It is possible to refer to existing .ini variables from within .ini files. Example: open_basedir = $ «:/new/dir» .

Scan directories

It is possible to configure PHP to scan for .ini files in a directory after reading php.ini . This can be done at compile time by setting the —with-config-file-scan-dir option. The scan directory can then be overridden at run time by setting the PHP_INI_SCAN_DIR environment variable.

It is possible to scan multiple directories by separating them with the platform-specific path separator ( ; on Windows, NetWare and RISC OS; : on all other platforms; the value PHP is using is available as the PATH_SEPARATOR constant). If a blank directory is given in PHP_INI_SCAN_DIR , PHP will also scan the directory given at compile time via —with-config-file-scan-dir.

Within each directory, PHP will scan all files ending in .ini in alphabetical order. A list of the files that were loaded, and in what order, is available by calling php_ini_scanned_files() , or by running PHP with the —ini option.

Assuming PHP is configured with --with-config-file-scan-dir=/etc/php.d, and that the path separator is . $ php PHP will load all files in /etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d php PHP will load all files in /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=:/usr/local/etc/php.d php PHP will load all files in /etc/php.d/*.ini, then /usr/local/etc/php.d/*.ini as configuration files. $ PHP_INI_SCAN_DIR=/usr/local/etc/php.d: php PHP will load all files in /usr/local/etc/php.d/*.ini, then /etc/php.d/*.ini as configuration files.

Источник

Php php web application configuration file code example

As for editing them using a web interface, if you are using XML or YAML, PHP’s excellent XML and YAML extensions should allow you to easily walk through the config file and modify the variables you require. In XML, your file could look like this Solution 2: You can simply create 2 php pages to manage this config file: 1.

Use web.config with php

Here is the web.config that I use to hide index.php, hope this will help.

       " appendQueryString="false" />   " matchType="IsFile" negate="true" /> " matchType="IsDirectory" negate="true" /> " />     

Hii thanks for your reply, but i got issue if use your code, i try another way because on index.php i also have catagory of the menus

Its working when i write as : mysite.com/sport (mysite.com/index.php?category=sport), mysite.com/clothes (mysite.com/index.php?category=clothes) etc..

but when i write as mysite.com/index then it treated as mysite.com/index.php?category=index

    " matchType="IsFile" ignoreCase="false" negate="true" /> " matchType="IsDirectory" ignoreCase="false" negate="true" /> " appendQueryString="true" />   " matchType="IsFile" ignoreCase="false" negate="true" /> " matchType="IsDirectory" ignoreCase="false" negate="true" /> " appendQueryString="true" />   " matchType="IsFile" negate="true" /> " matchType="IsDirectory" negate="true" /> .php" />  

Php web application configuration file Code Example, Also, if your app has configs you need on the client side (like for an Angular app), you can have this config.php file contain all your configs (centralized in one file instead of one for JavaScript and one for PHP). The trick would then be to have another PHP file that would echo only the client side info (to avoid showing info …

Best way to modify a custom configuration file via web interface?

For things like this, I would suggest some sort of a structured format such as XML or YAML instead of inventing your own.

The benefits of doing this are:

  • People have written encoders and parsers for those structured formats, so you can easily grab a library and use it with the language of your choice.
  • Structured formats can be easily portable across different applications.
  • Any third party can easily implement your configuration file into their application.

As for editing them using a web interface, if you are using XML or YAML, PHP’s excellent XML and YAML extensions should allow you to easily walk through the config file and modify the variables you require.

As for associating settings with a class, this can be easily solved by using XML or YAML.

In XML, your file could look like this

You can simply create 2 php pages to manage this config file: 1. read.php: Read the config file and display it in a friendly way 2. save.php: Save what you modify

The example code of read.php:

 if ($line=='%classend') < continue; >$opt = explode(': ', $line); $cfg[$curr][$opt[0]] = $opt[1]; > fclose($f); ?>    
$v): ?>

" value="" />