+/** Tell if we have some HTTP headers generated by a proxy */
+function has_http_forwarded()
+{
+ return
+ !empty($_SERVER['HTTP_X_FORWARDED_FOR']) ||
+ !empty($_SERVER['http_X_forwarded_for']);
+}
+
+/**
+ * Generate IP list from HTTP headers generated by a proxy
+ * @return array of IP strings
+ */
+function get_ip_list_http_forwarded()
+{
+ $ip_list = array();
+ if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+ $l = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
+ if ($l === false) {
+ return array();
+ }
+ foreach ($l as $ip) {
+ array_push($ip_list, preg_replace('/\s+/', '', $ip));
+ }
+ }
+ if (!empty($_SERVER['http_X_forwarded_for'])) {
+ $l = explode(',', $_SERVER['http_X_forwarded_for']);
+ foreach ($l as $ip) {
+ // Separate IP from port
+ $ipa = explode(':', $ip);
+ if ($ipa === false) {
+ continue;
+ }
+ $ip = $ipa[0];
+ array_push($ip_list, preg_replace('/\s+/', '', $ip));
+ }
+ }
+ return $ip_list;
+}
+