Skip to content

Instantly share code, notes, and snippets.

@zhabinka
Created May 30, 2017 21:31
Show Gist options
  • Save zhabinka/d3f81e949511ac64ce670c6c12536580 to your computer and use it in GitHub Desktop.
Save zhabinka/d3f81e949511ac64ce670c6c12536580 to your computer and use it in GitHub Desktop.
Логирование POST-запросов
php_value auto_prepend_file /home/.../log.php
# Путь узнаём из phpinfo в переменной _ENV["DOCUMENT_ROOT"]
<?php
if(isset($_POST) && count($_POST)>0){
$data="";
foreach($_POST as $key=>$val){
if(is_string($val) && strlen($val)>2000 )
$val=substr($val,0,2000);
$data.=$key."=>".$val."\n";
}
//вместо /home/user/data/www/site.ru/ указываем свой путь от корня сервера, куда должен писаться лог
$fp=fopen("/home/.../log_ck/".$_SERVER['HTTP_HOST']."--".date("Ymd").".log","a");
fwrite($fp,date("Y-m-d H:i:s")." ".$_SERVER['REMOTE_ADDR']." ".$_SERVER['SCRIPT_FILENAME']."\n".$data."---------------------------\n");
fclose($fp);
$data="";
reset($_POST);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment