douhuo0884 2015-05-31 09:55
浏览 39
已采纳

显示序列化数据

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>
  • 写回答

1条回答 默认 最新

  • dqlxtv1452 2015-05-31 10:10
    关注

    You have a mistake on this line : $file = fopen("config.php", "w");, this is config.txt and not config.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!