merged from MOODLE_15_STABLE: Clean up IP addresses from getremoteaddr. Otherwise we sometimes get weird results from proxies and inserts into mdl_log and mdl_user fail
This commit is contained in:
+10
-3
@@ -6334,17 +6334,24 @@ function unzip_show_status ($list,$removepath) {
|
||||
*/
|
||||
function getremoteaddr() {
|
||||
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
|
||||
return $_SERVER['HTTP_CLIENT_IP'];
|
||||
return cleanremoteaddr($_SERVER['HTTP_CLIENT_IP']);
|
||||
}
|
||||
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
return cleanremoteaddr($_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
}
|
||||
if (!empty($_SERVER['REMOTE_ADDR'])) {
|
||||
return $_SERVER['REMOTE_ADDR'];
|
||||
return cleanremoteaddr($_SERVER['REMOTE_ADDR']);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans a remote address ready to put into the log table
|
||||
*/
|
||||
function cleanremoteaddr($addr) {
|
||||
return preg_replace('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(.*)/','$1',$addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* html_entity_decode is only supported by php 4.3.0 and higher
|
||||
* so if it is not predefined, define it here
|
||||
|
||||
Reference in New Issue
Block a user