使用php和Javascript每天创建日志文件

使用php和Javascript每天创建日志文件,php,Php,我正在处理一个项目,我制作了一个代码来查看谁在访问我的站点 但我面临一个问题 代码运行良好,但它将所有信息收集在一个文件中 现在我只想每天做日志 我的意思是每天都会创建一个新文件,它会自动登录该文件 一天后,将创建一个新文件 这是我的密码: <?php $user_agent = $_SERVER['HTTP_USER_AGENT']; // Getting OS Name function getOS() { global $user_agent; $os_platfor

我正在处理一个项目,我制作了一个代码来查看谁在访问我的站点 但我面临一个问题 代码运行良好,但它将所有信息收集在一个文件中 现在我只想每天做日志 我的意思是每天都会创建一个新文件,它会自动登录该文件 一天后,将创建一个新文件

这是我的密码:

<?php
$user_agent     =   $_SERVER['HTTP_USER_AGENT'];
// Getting OS Name
 function getOS() { 
global $user_agent;
$os_platform    =   "Unknown OS Platform";
$os_array       =   array(
                        '/windows nt 10/i'     =>  'Windows 10',
                        '/windows nt 6.3/i'     =>  'Windows 8.1',
                        '/windows nt 6.2/i'     =>  'Windows 8',
                        '/windows nt 6.1/i'     =>  'Windows 7',
                        '/windows nt 6.0/i'     =>  'Windows Vista',
                        '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
                        '/windows nt 5.1/i'     =>  'Windows XP',
                        '/windows xp/i'         =>  'Windows XP',
                        '/windows nt 5.0/i'     =>  'Windows 2000',
                        '/windows me/i'         =>  'Windows ME',
                        '/win98/i'              =>  'Windows 98',
                        '/win95/i'              =>  'Windows 95',
                        '/win16/i'              =>  'Windows 3.11',
                        '/macintosh|mac os x/i' =>  'Mac OS X',
                        '/mac_powerpc/i'        =>  'Mac OS 9',
                        '/linux/i'              =>  'Linux',
                        '/kalilinux/i'          =>  'KaliLinux',
                        '/ubuntu/i'             =>  'Ubuntu',
                        '/iphone/i'             =>  'iPhone',
                        '/ipod/i'               =>  'iPod',
                        '/ipad/i'               =>  'iPad',
                        '/android/i'            =>  'Android',
                        '/blackberry/i'         =>  'BlackBerry',
                        '/webos/i'              =>  'Mobile',
                        '/Windows Phone/i'      =>  'Windows Phone'
                    );
foreach ($os_array as $regex => $value) { 
    if (preg_match($regex, $user_agent)) {
        $os_platform    =   $value;
    }
}   
return $os_platform;
}
// END of Getting OS
//
// Get browser
function getBrowser() {
global $user_agent;
$browser        =   "Unknown Browser";
$browser_array  =   array(
                        '/msie/i'       =>  'Internet Explorer',
                        '/firefox/i'    =>  'Firefox',
                        '/Mozilla/i'    =>  'Mozila',
                        '/Mozilla/5.0/i'=>  'Mozila',
                        '/safari/i'     =>  'Safari',
                        '/chrome/i'     =>  'Chrome',
                        '/edge/i'       =>  'Edge',
                        '/opera/i'      =>  'Opera',
                        '/OPR/i'        =>  'Opera',
                        '/netscape/i'   =>  'Netscape',
                        '/maxthon/i'    =>  'Maxthon',
                        '/konqueror/i'  =>  'Konqueror',
                        '/Bot/i'        =>  'BOT Browser',
                        '/Valve Steam GameOverlay/i'  =>  'Steam',
                        '/Googlebot/i'   =>  'GOOGLE Bot',
                        '/OrbitFox/i'   =>  'Orbit Fox Bot',
                        '/mobile/i'     =>  'Handheld Browser'
                    );
foreach ($browser_array as $regex => $value) { 
    if (preg_match($regex, $user_agent)) {
        $browser    =   $value;
    }
}
return $browser;
}
// END of getting browser
$user_os        =   getOS();
$user_browser   =   getBrowser();
// Comming soon part --- Maybe :D 

// Getting visitor IP address
$ip = $_SERVER['REMOTE_ADDR'];
// Getting where visitor come

// Hide ownr's IP address
$owner = "lol";   //Change $owner for something else, cuz someone can         simple read that by calling out $owner
 // change it for $absdfs5sd4 for example and change it down there 
$owner_country = "YOUR COUNTRY TAG FOR YOUR IP ↑"; //This u can leave how it is.

if($ip == $owner){ //Change it here 
    $ip = "Owner"; 
    $country = $owner_country;
    }
 //If that wasn't you, it woun't change IP address and it will find info about IP address
else{
    $details = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
    $country = $details->country;
 }

 $dataTime = date_default_timezone_set("Asia/Dhaka");
 $dataTime = date_default_timezone_get();
 $dateTime = date('D M d, Y  h:i:s a');

$file = "/home/shakilofficial/public_html/vtinfo/mainindex.html";
 $file = fopen($file, "a");
 $data = "<p>##################</p><br><p><b>User Time </b>: $dateTime </p><br><pre> <b> User IP </b>: $ip <b> Browser</b>: $user_browser <br> <b> User OS </b>: $user_os <b> Users-From </b>: $country <br><br><b> User-agent </b>: $user_agent </pre>";

fwrite($file, $data);
 fclose($file);

 ?>

<html>
 <body>
 <h1>Its Okh</h1>

 </body>
 </html>

再装入一个变量,如$date一个:

$file = "/home/shakilofficial/public_html/vtinfo/mainindex{$newTime}.html";
然后将其添加到您的文件名中:

$file = "/home/shakilofficial/public_html/vtinfo/mainindex.html";

因此,您每天都会有一个不同的文件,文件名也不一样

再装入一个变量,如$date一个:

$file = "/home/shakilofficial/public_html/vtinfo/mainindex{$newTime}.html";
然后将其添加到您的文件名中:

$file = "/home/shakilofficial/public_html/vtinfo/mainindex.html";

因此,您每天都会有一个不同的文件,文件名也不同,最简单的方法是替换该行

$file = "/home/shakilofficial/public_html/vtinfo/mainindex-".date('Y-m-d').".html";
有点类似于


这将把一个日期的所有请求放入一个适当命名的文件。

最简单的方法是替换该行

$file = "/home/shakilofficial/public_html/vtinfo/mainindex-".date('Y-m-d').".html";
有点类似于


这将把一个日期的所有请求放入一个适当命名的文件。

您的问题是什么?什么不起作用?假设您的Web服务器是Apache,为什么不解析它生成的日志呢?对于IIS、Zope或任何您拥有的Web服务器来说,情况可能都是如此。您的问题是什么?什么不起作用?假设您的Web服务器是Apache,为什么不解析它生成的日志呢?对于IIS、Zope或任何您拥有的Web服务器来说,情况也很可能如此。。