For example, I have a config.php:
//default config
$name = 'default name';
$mail = 'default mail';
And I want to use a form to let the user edit the variable, everything is just like the using database, but in this case the difference is it is implement on a PHP file
So, after I get $_POST['name']; $_POST['mail'];, how can I modify the variable and save it in that PHP?
The config file needs to be in PHP? You can hack together a quick configuration array into an external file using
var_exportThe config file
config.phpLoading/saving the config file:
As with any user input you should be sure to filter the input against a whitelist to weed out dangerous data. For instance,
preg_replace('/\W/', '', $_POST['name'])will remove unsafe data (non-word characters) from the user-supplied values.