为 WordPress 生成网站访问日志 | 周良博客

我是创始人李岩:很抱歉!给自己产品做个广告,点击进来看看。  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
make_log_file();
function make_log_file(){
//log文件名
$filename = 'mylogs.txt';
//去除rc-ajax评论以及cron机制访问记录
if(strstr($_SERVER["REQUEST_URI"],"rc-ajax")== false
&& strstr($_SERVER["REQUEST_URI"],"wp-cron.php")== false ) {
$word .= date('mdHis',$_SERVER['REQUEST_TIME'] + 3600*8) . " ";
//访问页面
$word .= $_SERVER["REQUEST_URI"] ." ";
//协议
$word .= $_SERVER['SERVER_PROTOCOL'] ." ";
//方法,POST OR GET
$word .= $_SERVER['REQUEST_METHOD'] . " ";
//$word .= $_SERVER['HTTP_ACCEPT'] . " ";
//获得浏览器信息
$word .= getbrowser(). " ";
//传递参数
$word .= "[". $_SERVER['QUERY_STRING'] . "] ";
//跳转地址
$word .= $_SERVER['HTTP_REFERER'] . " ";
//获取IP
$word .= getIP() . " ";
$word .= "\n";
$fh = fopen($filename, "a");
fwrite($fh, $word);
fclose($fh);
}
}
//获取IP地址,网上现成代码
function getIP() //get ip address
{
if (getenv('HTTP_CLIENT_IP'))
{
$ip = getenv('HTTP_CLIENT_IP');
}
else if (getenv('HTTP_X_FORWARDED_FOR'))
{
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
else if (getenv('REMOTE_ADDR'))
{
$ip = getenv('REMOTE_ADDR');
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
//获取浏览器信息,移动端,平板电脑数据还未加上。
function getbrowser()
{
$Agent = $_SERVER['HTTP_USER_AGENT'];
$browser = '';
$browserver = '';

if(ereg('Mozilla', $Agent) && ereg('Chrome', $Agent))
{
$temp = explode('(', $Agent);
$Part = $temp[2];
$temp = explode('/', $Part);
$browserver = $temp[1];
$temp = explode(' ', $browserver);
$browserver = $temp[0];
$browserver = $browserver;
$browser = 'Chrome';
}
if(ereg('Mozilla', $Agent) && ereg('Firefox', $Agent))
{
$temp = explode('(', $Agent);
$Part = $temp[1];
$temp = explode('/', $Part);
$browserver = $temp[2];
$temp = explode(' ', $browserver);
$browserver = $temp[0];
$browserver = $browserver;
$browser = 'Firefox';
}
if(ereg('Mozilla', $Agent) && ereg('Opera', $Agent))
{
$temp = explode('(', $Agent);
$Part = $temp[1];
$temp = explode(')', $Part);
$browserver = $temp[1];
$temp = explode(' ', $browserver);
$browserver = $temp[2];
$browserver = $browserver;
$browser = 'Opera';
}
if(ereg('Mozilla', $Agent) && ereg('MSIE', $Agent))
{
$temp = explode('(', $Agent);
$Part = $temp[1];
$temp = explode(';', $Part);
$Part = $temp[1];
$temp = explode(' ', $Part);
$browserver = $temp[2];
$browserver = $browserver;
$browser = 'Internet Explorer';
}
if($browser != '')
{
$browseinfo = $browser.' '.$browserver;
}
else
{
$browseinfo = $_SERVER['HTTP_USER_AGENT'];
}
return $browseinfo;
}

随意打赏

提交建议
微信扫一扫,分享给好友吧。