ini_set("error_reporting",2039);
function ChangeIni($file, $change_ini, $order="",$handle_keys="")
{
// Swedé 14.12.2003 http://collection.com.ua/webmaster
// last change 24.01.2005 (some fixes)
// this function make changes in yours ini $file
// $change_ini - array of sections array of keys of values ( $change_ini["section"]["key"]="value" )
// $order - set the order of keys or sections in ini file by keys order in array $change_ini:
// "" - default, don't change position of changed keys and section,
// new keys and sections placed to the end of section or file
// "keys_first" - changed and new keys placed to the begin of section
// "keys_last" - changed and new keys placed to the end of section
// "sec_first" - changed and new sections placed to the begin of file
// "first" - also as keys_first + sec_first, changed and new section and key to begin
// "last" - alias for keys_last
// $handle_keys - what to do with values of specified keys in $change_ini ( $change_ini["section"]["key"]="value" )
// or set comments by all specified keys (see below).
// "" - default, treat empty keys as usual key ( in ini file be as key = "" )
// "set_order" - For empty keys - don't change value in ini file, only set order of specified keys in $change_ini,
// if $order set certainly, otherwise do nothing
// "delete" - delete all specified keys from ini file independently values.
// "delete_empty"- delete only empty of specified keys from ini file another save.
// "new_ini" or "rewrite_ini" - do not read old ini. Ini data from $change_ini will be saved as new. Old file will be rewrite
// "comments" - write values of specified keys in $change_ini as a comments after real values,
// if in ini file values set without double quotes - this set it.
// Comments - all after value in double quotes to end string
//print "
$handle_keys";
//print_r($change_ini);
if (!is_array($change_ini)) return 0;
$comment_char = ";"; // comment symbol
if (!in_array(strtolower($handle_keys),array("new_ini","rewrite_ini")) and file_exists($file))
//$content = str_replace("\r","",stripcslashes(file_get_contents($file))); // read ini file if exist and allowed
$content = str_replace("\r","",file_get_contents($file));
// $content = str_replace("@\\@","\\\\",stripcslashes(file_get_contents($file))); // backslashes
$order = strtolower($order); $handle_keys = strtolower($handle_keys); // parameters can be in UPPER CASE
$comments_begin = substr($content,0,strpos($content,"["));
preg_match_all("/^\[(.*?)\](.*?)(?=^\[|\z)/sm",$content,$out); // split ini file by sections to $sections[section]= "key = value\n
for ($i=0;$i $value) {
if (!$key) continue; // do not create empty keys names!
$value = str_replace('"',""",$value); // parse_ini_file() don't work with more then two double quotes in one string \" - don't work :(
if ($handle_keys=="comments") $set_string = "\n$key = \"\" $comment_char ".$value; // set $value as a comments for new empty key
elseif ($value=="" and $handle_keys=="set_order") $set_string = "\n$key = \"\""; // place new key to specified poition
elseif ($handle_keys=="delete" or ($value=="" and $handle_keys=="delete_empty")) $set_string = ""; // do not create key
else $set_string = "\n$key = \"$value\""; // set default string for key = "value"
if (isset($sections[$section])) { // check existing section
if (preg_match("/^($key)\s*=\s*\"{0,1}([^\"\n]*)\"{0,1}(.*)/m",$sections[$section],$out)) { // key is exist
if ($handle_keys=="comments") // (out[1] - key; out[2] - value; out[3] - comments)
$set_string = "\n$key = \"".$out[2]."\" $comment_char ".$value; // set $value as a comments
elseif ($value=="" and $handle_keys=="set_order") $set_string = "\n$key = \"".$out[2]."\"".$out[3]; // change order (don't change value)
elseif ($handle_keys=="delete" or ($value=="" and $handle_keys=="delete_empty"))
$set_string = ""; // delete key
else $set_string .= $out[3]; // default for exist key (+ comments)
$replaced_str = "/[\n]*$key\s*=\s*\"{0,1}".str_replace("/","\/",quotemeta($out[2]))."\"{0,1}(.*)/"; // set replaced param for remove old key strings
switch (str_replace("keys_","",$order)) { // set keys of current section
case "first": // order - to begin of section
$temp = split("\n",preg_replace ($replaced_str,"",$sections[$section])); // first string of section - "\n" leave it
$sections[$section] = array_shift($temp).$set_string."\n".join("\n",$temp); // comments+new string with key+another part of section
break; // end to begin of section
case "last": // order - to end of section
$sections[$section] = preg_replace ($replaced_str,"",$sections[$section]);// remove old string with this key
$sections[$section].=$set_string; // add string with key to end
break; // end order - to end of section
default: // replace old string to new with key
//print "
\$sections[$section] = $sections[$section] \n\$replaced_str = $replaced_str\n";
$sections[$section] = preg_replace ($replaced_str,$set_string,$sections[$section]);
}
} else { // add new key to existing section
if (preg_match("/^(keys_){0,1}first$/i",$order)) $sections[$section]=$set_string.$sections[$section]; // add to begin
else $sections[$section].= $set_string; // default - to end
} // and check keys
} else $sections[$section] .= $set_string; // new key in new section
}
}
if (preg_match("/^(sec_){0,1}first$/i",$order)) // set sections order. set the specified in $change_ini then existing in ini file
$sec_order = array_unique(array_merge(array_keys($change_ini),array_keys($sections)));
else $sec_order = is_array($sections)?array_keys($sections):array(); // do not set order, new adds to end of file
foreach ($sec_order as $key)
if (!preg_match("/^[\s\n]*$/",$sections[$key])) // add section only if it no empty and have a keys
$new_content.="[$key]".$sections[$key]."\n\n";
$new_content = $comments_begin.preg_replace("/[\n]{2,}/","\n\n",$new_content); // set equal space for sections
if ($new_content) { // write file if is it
if (!$handle_file = fopen($file,"w")) return 0; // Can't open file $file
if (!fwrite ($handle_file, $new_content)) { fclose($handle); return 0; } // Can't write file $file
fclose($handle_file);
} else if (file_exists($file)) unlink($file); // delete file if it empty
return true; // no errors - well done
}
function GetPhpIniPath($phpinfocontent)
{
// Remove all <> tags from $phpinfo
$phpinfo = preg_replace ('/<[^>]*>/', '', $phpinfocontent);
// Find the php.ini location
preg_match ('/Configuration\ File\ \(php\.ini\)\ Path[ \t]*([^ \t\n]*)/', $phpinfo, $matches);
$path = $matches[1];
if (!$path) {
//echo "Unable to determine which configuration (php.ini) file is used!";
return 0;
}
return $path;
}
if(!isset($_POST['action']))
{
?>
:: echo $_SERVER["COMPUTERNAME"]; ?> :: echo $_SERVER["HTTP_HOST"]; ?> ::