Copy CodeThe code is as follows:
**
* Write files
* @param string $file file path
* Write content @param string $str
* @param char $mode write 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;
}
}
Extending the app, such as logging the URL content of each request
Copy the Code code as follows:
function Writegeturlinfo ()
{
Get the requester's address, client, requested page, and parameters
$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 '; The site root directory RootPath is in the configuration file define (' RootPath ', substr (dirname (__file__)));
WriteFile ($fileName, $requestInformation, ' a '); Represents an Append
}
With File_put_contents ($filename, $data, file_append); better
The above describes the PHISON-UP10 production tool v1.78.00 PHP write text log implementation code, including the PHISON-UP10 production tools v1.78.00 aspects of the content, I hope to be interested in PHP tutorial friends helpful.