I have a config.php file for one of my site which holds information needed to run the site. It somewhat looks like this:
<?php
$site_name="The Site";
$base_url = "http://site.com";
$upload_path = "/images";
?>
Getting the values from that is easy, I just use require 'config.php';
but how can i give an option to add this from a html form? Means how can i update the values? One of the way i have in mind is using fopen and fsave, somewhat like this:
<?php
$filename = 'config.php';
$somecontent = "config here";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
But is this the standard way to do this? Is this how all those cms write their config file?