|
|
|
ต้องการฝั่ง log file ไว้ใน web services ควรทำยังไง |
|
|
|
|
|
|
|
function
Code (PHP)
function logIP(){
function get_ip()
{
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
$ip = "CLIENT_IP :: ".get_ip()." "; //IP CLIENT
date_default_timezone_set('Asia/Bangkok');
//$event = $txt_name." ".$txt_surname." praphat ".$dep_name." "; //
$log_date = "DATETIME :: ".date('Y-m-d H:i:s') ." "; //datetime
$query_str = "QUERY_STR :: ".$_SERVER["QUERY_STRING"]."\r\n"; //query_str
$ip_server= "SERVER_IP :: ".$_SERVER['SERVER_NAME']." "; //IP_SERVER
$URL="URL:: ".$_SERVER["PHP_SELF"]." ";
/*
$sql2="insert into log (log_ip,log_event,log_date) values ('$ip','$event','$log_date')";
$query2 = mysql_query($sql2);
*/
$strFileName = "../log/$_SERVER[PHP_SELF].log.txt";
$objFopen = fopen($strFileName, 'a');
fwrite($objFopen, $log_date);
fwrite($objFopen,$ip);
//fwrite($objFopen, $event);
fwrite($objFopen, $ip_server);
fwrite($objFopen, $URL);
fwrite($objFopen, $query_str);
//
fclose($objFopen);
}
?>
เริยกใช้งาน แต่ไม่แสดงผล
Code (PHP)
include('logFunction.php');
$Log = logIP();//fonction Log
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2014-09-10 10:15:25 |
By :
praphat_thekop |
View :
682 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อันที่จริงไม่น่าจะยากน่ะครับ ลองไล่ echo ดูว่ามันทำงานตรงไหน ถึงตรงไหน แล้วหยุดที่ตรงไหน
|
|
|
|
|
Date :
2014-09-11 09:53:33 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมแก้ได้แล้วครับ สรปติด permission ครับ
ขออภัยทุกท่านนะครับ
|
|
|
|
|
Date :
2014-09-11 11:00:13 |
By :
praphat_thekop |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2014-09-11 11:56:52 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|