zoukankan      html  css  js  c++  java
  • PHP保存本地日志文件

    **
    * 写文件
    * @param    string  $file   文件路径
    * @param    string  $str    写入内容
    * @param    char    $mode   写入模式
    */
    function writeFile($file,$str,$mode='w')
    {
        $oldmask = @umask(0);
        $fp = @fopen($file,$mode);
        @flock($fp, 3);
        if(!$fp)
        {
            Return false;
        }
        else
        {
            @fwrite($fp,$str);
            @fclose($fp);
            @umask($oldmask);
            Return true;
        }
    }

    扩展应用,比如记录每次请求的url内容

    function writeGetUrlInfo()
    {

      //获取请求方的地址,客户端,请求的页面及参数
       $requestInformation = $_SERVER['REMOTE_ADDR'].', '.$_SERVER['HTTP_USER_AGENT'].', http://'.$_SERVER['HTTP_HOST'].htmlentities        ($_SERVER['PHP_SELF']).'?'.$_SERVER['QUERY_STRING']." "; 
       $fileName = RootPath.'/log/'.date('Y-m-d').'.log'; //网站根目录RootPath是在配置文件里define('RootPath', substr(dirname(__FILE__))); 
       writeFile($fileName, $requestInformation, 'a'); //表示追加
    }

     
  • 相关阅读:
    洛谷 P4861 按钮
    《情人》
    bzoj1019: [SHOI2008]汉诺塔(dp)
    hdu5698瞬间移动(组合数,逆元)
    poj Code(组合数)
    组合数 牛顿二项式定理 杨辉三角
    8.22 NOIP 模拟题
    codevs2495 水叮当的舞步(IDA*)
    codevs 2541 幂运算(迭代加深搜索)
    较复杂搜索,剪枝
  • 原文地址:https://www.cnblogs.com/HuiLove/p/4923776.html
Copyright © 2011-2022 走看看