let's say i have 2 files: a.php and b.php
a.php
$value = "test";
i would like to update the $value by using b.php. i want to run b.php and change a.php like that:
$value = "changed";
here is the code to open a php file using php :
$file = "/home/dir/file.php";
$fs = fopen( $file, "a+" ) or die("error when opening the file");
while (!feof($fs)) {
$contents .= fgets($fs, 1024);
}
fclose($fs);
now you can take the $contents and modify it to however you would like and then save it. here is how you can save it :
$fs = fopen( $_POST["file"], "a+" ) or die("error when opening the file");
fwrite($fs, $updatedContents);
fclose();
$updatedContents is the updated content