function logg($message,$type='') {
$log = "日期时间:".date('Y-m-d h:i:s')."\n";
$log .= "IP地址:".getIp()."\n";
$log .= "请求路径:".$_SERVER['SCRIPT_NAME']."\n";
$log .= "Gat参数:".str_replace('&', '&', $_SERVER['QUERY_STRING'])."\n";
$log .= "POST数据:".json_encode($_POST, true)."\n";
$log .= "自定义日志:".(is_array($message) ? json_encode($message, true) : $message)."\n";
$log .= "\n";
define('BASE_PATH',str_replace('\\','/',realpath(dirname(__FILE__).'/'))."/");
$path = BASE_PATH.'/log/'.date('Ym');
@mkdir($path,0777,true);
$filename = $path.'/'.date('d');
if($type) $filename.='-'.$type;
$filename.='.log';
@file_put_contents($filename, $log,FILE_APPEND);
return ;
}
function getip() {
static $ip = '';
$ip = $_SERVER['REMOTE_ADDR'];
if(isset($_SERVER['HTTP_CDN_SRC_IP'])) {
$ip = $_SERVER['HTTP_CDN_SRC_IP'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP']) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
foreach ($matches[0] AS $xip) {
if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
$ip = $xip;
break;
}
}
}
return $ip;
}