I have a config.php file with several define via a form.
If there is one define it like this:
define("NAME","Rodrigo");
and another like this:
define("MEU_NOME","Rodrigo");
And in my HTML I have only ONE input:
<?php include(config.php) ?>
<input type="text" id="NAME" value="<?=NAME?>" name="MSSQL_Pass">
If the input sends the name "Danilo", it records that name in both sets, even though I do not have another input with the ID and NAME equal to the one I want to record.
This is my role:
function write(){
$file = fopen("config.php","rb");
$MainContents = "";
while(!feof($file)) $MainContents .= fgets($file);
fseek($file, 0);
while(!feof($file))
{
$Main = fscanf($file,'%[^;]');
if(strpos($Main[0],"//") === false && strpos($Main[0],"?") === false && isset($Main[0]))
{
$data = explode("\",",$Main[0]);
$const = str_replace("define(\"", "", $data[0]);
$value = str_replace(")", "", $data[1]);
$myVar = trim($const);
if(!empty($_POST[$myVar]))
{
$new = ($_POST[$myVar] == "true" || $_POST[$myVar] == "false") ? $_POST[$myVar] : "\"" . $_POST[$myVar] . "\"";
$MainContents = str_replace($value, " " . $new ,$MainContents);
}
}
}
fclose($file);
$file = fopen("config.php","wb");
fwrite($file, $MainContents);
fclose($file);
echo " <div class=\"success-box\">Configurações salvas com sucesso!</div>";
}
How can I resolve this?