+/**
+ * Extracts the XFF string from the request header
+ * Checks first for "X-Forwarded-For", then "Client-ip"
+ * Note: headers are spoofable
+ * @return string
+ */
+function wfGetForwardedFor() {
+ if( function_exists( 'apache_request_headers' ) ) {
+ // More reliable than $_SERVER due to case and -/_ folding
+ $set = array ();
+ foreach ( apache_request_headers() as $tempName => $tempValue ) {
+ $set[ strtoupper( $tempName ) ] = $tempValue;
+ }
+ $index = strtoupper ( 'X-Forwarded-For' );
+ $index2 = strtoupper ( 'Client-ip' );
+ } else {
+ // Subject to spoofing with headers like X_Forwarded_For
+ $set = $_SERVER;
+ $index = 'HTTP_X_FORWARDED_FOR';
+ $index2 = 'CLIENT-IP';
+ }
+
+ #Try a couple of headers
+ if( isset( $set[$index] ) ) {
+ return $set[$index];
+ } else if( isset( $set[$index2] ) ) {
+ return $set[$index2];
+ } else {
+ return null;
+ }
+}
+
+/**
+ * Returns the browser/OS data from the request header
+ * Note: headers are spoofable
+ * @return string
+ */
+function wfGetAgent() {
+ if( function_exists( 'apache_request_headers' ) ) {
+ // More reliable than $_SERVER due to case and -/_ folding
+ $set = array ();
+ foreach ( apache_request_headers() as $tempName => $tempValue ) {
+ $set[ strtoupper( $tempName ) ] = $tempValue;
+ }
+ $index = strtoupper ( 'User-Agent' );
+ } else {
+ // Subject to spoofing with headers like X_Forwarded_For
+ $set = $_SERVER;
+ $index = 'HTTP_USER_AGENT';
+ }
+ if( isset( $set[$index] ) ) {
+ return $set[$index];
+ } else {
+ return '';
+ }
+}
+
+/**
+ * Work out the IP address based on various globals
+ * For trusted proxies, use the XFF client IP (first of the chain)
+ * @return string
+ */