1

I'm trying to change some options from php.ini using zend. I have my own empty extension, it works, uses global variables and initializes well, so everything seems fine...

But i can't find an answer:

Is it possible to change php.ini globals from within extension itself? I wonder if i could change system core 'disable_functions'?

marcio
  • 10,002
  • 11
  • 54
  • 83
Dmitry
  • 55
  • 8

1 Answers1

1

this is my code(c++) for change php.ini in extension. it will be ignore event on_modify. may be it can help you.

bool hack_ini_set (std::string _name, std::string _val)
{
    zend_ini_entry *ini_entry;
    char *duplicate; 

    zend_bool modifiable;
    zend_bool modified;

    char* name = const_cast<char*> (_name.c_str()); 
    uint name_length = strlen(name)+1;
    char* new_value= const_cast<char*> (_val.c_str());
    uint new_value_length = strlen(new_value);


    if (zend_hash_find(EG(ini_directives), name, name_length, (void **) &ini_entry) == FAILURE) {
        return false;
    }

    modifiable = ini_entry->modifiable;
    modified = ini_entry->modified;

    if (!EG(modified_ini_directives)) {
        ALLOC_HASHTABLE(EG(modified_ini_directives));
        zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0);
    }

    if (!modified) {
        ini_entry->orig_value = ini_entry->value;
        ini_entry->orig_value_length = ini_entry->value_length;
        ini_entry->orig_modifiable = modifiable;
        ini_entry->modified = 1;
        zend_hash_add(EG(modified_ini_directives), name, name_length, &ini_entry, sizeof(zend_ini_entry*), NULL);
    }

    duplicate = estrndup(new_value, new_value_length);

    if (modified && ini_entry->orig_value != ini_entry->value) {
        efree(ini_entry->value);
    }
    ini_entry->value = duplicate;
    ini_entry->value_length = new_value_length;


    return true;
}

you can see more in file zend_ini.c

ZEND_API int zend_alter_ini_entry_ex(char *name, uint name_length, char *new_value, uint new_value_length, int modify_type, int stage, int force_change TSRMLS_DC)
Mr Jerry
  • 1,686
  • 3
  • 14
  • 22