Generate your own LOG file with PHP_PHP tutorial

WBOY
Release: 2016-07-21 16:10:19
Original
929 people have browsed it


If your server doesn't allow you to read its LOG file, then you have to stop and analyze your visitors? Make your own LOG file!
All you have to do is count the actual number of clicks in PHP, no errors, no errors like '304 Not Modified' and 'Internal Server Error'. Your code will generate its own LOG file.



/* User-defined variables*/
$logfile = "clf.log"; /*Where the LOG file is written*/
$timezone = "+0100"; /* Timezone correction */
$lookup_size = true; /* Set file permissions*/
$document_root = "/usr/local/apache/share/htdocs";

/* It may or may not count the same client
* The $document_root variable must be set to work
*/

function write_to_log($ str) {
if($fd = @fopen($GLOBALS[ "logfile"], "a")) {
fputs($fd, $str);
fclose($fd);
}
}

function get_var($name,$default) {
if($var = getenv($name)) {
return $var;
} else {
return $default;
}
}

if($remote_host = get_var( "REMOTE_HOST", false)) {
$remote_host = get_var( "REMOTE_ADDR", " -");
}
$remote_user = get_var( "REMOTE_USER", "-");
$remote_ident = get_var( "REMOTE_IDENT", "-");
$server_port = get_var( "SERVER_PORT", 80);
if($server_port!=80) {
$server_port = ":" . $server_port;
} else {
$server_port = "";
}
$server_name = get_var( "SERVER_NAME", "-");
$request_method = get_var( "REQUEST_METHOD", "GET");
$request_uri = get_var( "REQUEST_URI", "") ;
$user_agent = get_var( "HTTP_USER_AGENT", "");
if($lookup_size == true && $document_root) {
$filename = ereg_replace( "?.*", "", $ request_uri);
$filename = "$document_root$filename";
if(!$size = filesize($filename)) {
$size = 0;
}
} else {
$size = 0;
}

$date = gmdate( "d/M/Y:H:I:s");
$log = "$remote_host $remote_ident $ remote_user [$date $timezone] "".
"$request_method http://$server_name$server_port$request_uri" 200 $sizen";

write_to_log($log);

?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/314242.htmlTechArticleIf your server does not allow you to read its LOG file, then you have to stop and analyze your visitors? Make your own LOG file! All you have to do is count the actual clicks in PHP...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!