**
* 写文件
* @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']."\n";
$filename = rootpath.'/log/'.date('y-m-d').'.log'; //网站根目录rootpath是在配置文件里define('rootpath', substr(dirname(__file__)));
writefile($filename, $requestinformation, 'a'); //表示追加
}
用file_put_contents($filename,$data,file_append);更佳
如对本文有疑问,
点击进行留言回复!!
相关文章:
-
-
-
-
-
-
-
荐
数据库的设计
数据库的设计一 为什么需要规范的数据库设计数据库设计的步骤收集信息标识实体标识每个实体需要存储的详细信息标识实体...
[阅读全文]
-
-
-
-
网友评论