正在显示的序列化数据

Serialized data being displayed

我需要为我的应用程序制作一个配置文件,但我偶然发现了一个问题,我试图解决它但找不到问题,这里的代码有效,除了一件事,每当我提交形式,它会保存数据,但当它重新加载时,它只会显示存储在 config.txt.

中的序列化数据

有谁知道为什么会这样,我该如何解决

感谢您的帮助 -oedze

编辑:更清楚地解释: idea是config.txt里面存的数据都会在表格里输入,不用不断的加,可以看到是什么值。当您按下提交按钮时,页面会将所有数据保存在 $config 数组中,然后将其保存在 config.txt 中,完成后,它将重新加载页面,因此 post 数据将从用户缓存中删除。但是,每当页面重新加载时,它都会显示 a:1:{s:9:"groupname";s:4:"test";} 而不是 html 页面

<!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>

您在这一行有误:$file = fopen("config.php", "w");,这是 config.txt 而不是 config.php