I am working on a file that should replace a variable in another file. So far I tried:
$File = "$dir/submit.php";
$fh = fopen($File, 'r') or die("Couldn't edit the Config-file. Please report to admin.");
$chosendb = str_replace('$chosendb = comments;','$chosendb = wuhuws_$dir;','$chosendb');
fclose($fh);
$dir is a user input.
comments is a table in the database that need to replaced with the prefix_$dir.
What do I do wrong?
You’re forgetting to write to the file again.
However, as Zerkms said (or atleast intended to 😉 ), it’s generally a bad idea to edit PHP with PHP, especially since you’ll find a hard time debugging your script later since its code dynamically changes upon runtime.
Is there any reason why you cannot include this file and manually set these variables, like: