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.

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

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP