Log: fix logging the right IP address when install behind a reverse proxy
This commit is contained in:
parent
bb62e5b53b
commit
6aa4113310
1 changed files with 15 additions and 1 deletions
16
src/Log.php
16
src/Log.php
|
@ -133,6 +133,20 @@ class Log {
|
|||
set_exception_handler(array('EesyPHP\\Log', 'exception'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get remote IP address
|
||||
* @return string
|
||||
*/
|
||||
public static function get_remote_addr(){
|
||||
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER))
|
||||
return $_SERVER["HTTP_X_FORWARDED_FOR"];
|
||||
if (array_key_exists('REMOTE_ADDR', $_SERVER))
|
||||
return $_SERVER["REMOTE_ADDR"];
|
||||
if (array_key_exists('HTTP_CLIENT_IP', $_SERVER))
|
||||
return $_SERVER["HTTP_CLIENT_IP"];
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message
|
||||
* @param string $level The message level (key of self :: $levels)
|
||||
|
@ -171,7 +185,7 @@ class Log {
|
|||
$msg = array(
|
||||
date('Y/m/d H:i:s'),
|
||||
$_SERVER['REQUEST_URI'],
|
||||
$_SERVER['REMOTE_ADDR'],
|
||||
self :: get_remote_addr(),
|
||||
);
|
||||
if (Auth::enabled())
|
||||
$msg[] = (Auth::user()?Auth::user():'anonymous');
|
||||
|
|
Loading…
Reference in a new issue