Home  >  Article  >  Backend Development  >  PHP中Post和Get获取数据写入文件中

PHP中Post和Get获取数据写入文件中

WBOY
WBOYOriginal
2016-06-23 13:49:201606browse

有时候Post或者Get传过来的数据我们不知道它是个什么样的形式,它可能是JSON格式或者就是简单提交过来的数据,这时候我们可以把他写入到文本中,就可以看到传过来的数据是什么格式了。

    $val = "";    $currentDateTime  =  date('YmdHis',time());    $currentDate =  date('Ymd',time());    $fileName = "ioslog/".$currentDate;//文件名称    @$data = fopen($fileName,'a+');//添加不覆盖,首先会判断这个文件是否存在,如果不存在,则会创建该文件,即每天都会创建一个新的文件记录的信息    $val.= $currentDateTime;    if($_POST){        $val.='|POST'.'|'.$_POST."\n";        foreach($_POST as $key =>$value){            $val .= '|'.$key.":".$value;        }    }else{        $val.='|GET'.'|'.$_GET."\n";        foreach($_GET as $key =>$value){                $val .= '|'.$key.":".$value;            }    }    $val.= "\n";    fwrite($data,$val);//写入文本中    fclose($data);


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:appserv 配置多站点Next article:关于 herf