I need to make a config file for my application, but i stumbled upon a problem, i tried to solve it but couldn't find the problem, the code here works, except for one thing, whenever i submit the form, it will save the data, but when it reloads it will just show the serialized data stored in config.txt.
Does anyone know why this happens and how i can solve it
Thanks for your help -oedze
edit: to explain more clearly: The idee is that the data stored in config.txt will all be inputed in the form, so you dont have to constantly add it, and you can see what the values are. when you press the submit button, the page will save all the data in the $config array, after that it will save it in config.txt, when that is done, it will reload the page, so the post data will be removed from the users cache. But, whenever the page reloads, it's showing something like a:1:{s:9:"groupname";s:4:"test";} instead of the html page
<!DOCTYPE html>
<html>
<head>
<?php
function getConfig(){
$file = fopen("config.txt", "r");
$fileData = fread($file, filesize("config.txt"));
fclose($file);
$config = unserialize($fileData);
return $config;
}
function saveConfig($config){
$file = fopen("config.php", "w");
fwrite($file, serialize($config));
fclose($file);
}
if(isset($_GET["updateConfig"])){
$config = array();
foreach($_POST as $key => $value){
$config[$key] = $value;
}
saveConfig($config);
header("Location: config.php");
}else{
$config = getConfig();
}
?>
</head>
<body>
<h1>Configuratie</h1>
<form method="post" action="config.php?updateConfig">
<table>
<tr class="optionsRow"><td class="optionsData">Groupname:</td><td class="optionsData"><input type="text" name="groupname" value="<?php $config["groupname"]?>"></td></tr>
</table>
<input type="Submit" value="Opslaan">
</form>
</body>
</html>