duandang9434 2017-02-15 21:19
浏览 58
已采纳

如何将$ _GET数据保存到PHP文件中

I'm trying to save all key values from the GET parameters, but its not writing anything to the file.

foreach ($_GET as $key => $value) {
   $contents = $key . " => " . $value . "<br>";
   echo($contents);
   file_put_contents("./test.log", $contents, FILE_APPEND);
}
  • 写回答

3条回答 默认 最新

  • dongshao8566 2017-02-15 21:25
    关注

    Don't use file_put_contents() inside loop. Put it outside:-

    $contents='';
    foreach ($_GET as $key => $value) {
        $contents .= $key . " => " . $value . "
    "; // or use `"
    "`            
    }
    file_put_contents("./test.log", $contents, FILE_APPEND);
    

    Note:- Check that file have write permission (644) + folder in which this file lies have the permission too (777) and path of the file is correct.

    Below are the screen-shots of working code at my local end:- http://prntscr.com/e98o04 And http://prntscr.com/e98oco

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料