Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is possible to add custom fields to PHP ini file?

Tags:

php

I want to know if is possible to add custom fields to the PHP ini file and get it with the ini_get function.

This code works fine:

;PHP ini file
mysqli.default_host=localhost

# PHP code
ini_get('mysqli.default_host') 

But I want to do something like this (isn't working):

;PHP ini file
my_custom_field=custom_value

# PHP code
ini_get('my_custom_field') 

Is possible to do this? Because when I do this to custom fields, it returns false.

like image 414
Renato Dinhani Avatar asked Jun 05 '12 17:06

Renato Dinhani


1 Answers

php.ini is for PHP configuration, unless you are making an extension (written in C) you probably shouldn't add new options to it. If you are making a configuration for a specific site/application create your own config.ini file inside that project's root. You can then use parse_ini_file to get the values from it.

If you really must add custom entries to your php.ini you can get them using get_cfg_var, not ini_get.

like image 80
Paul Avatar answered Sep 22 '22 12:09

Paul