PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / http / remote-address / class-classic-remote-address.php

class-classic-remote-address.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at src/component/http/remote-address/class-classic-remote-address.php

83 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles retrieval of client IP addresses from HTTP headers.
4 *
5 * @package WP_Defender\Component\Http\Remote_Address
6 */
7
8 namespace WP_Defender\Component\Http\Remote_Address;
9
10 use WP_Defender\Traits\IP;
11
12 /**
13 * Older way of getting the client/Remote IP address on HTTP request.
14 */
15 class Classic_Remote_Address {
16
17 use IP;
18
19 /**
20 * List of HTTP headers that may contain the client IP address.
21 *
22 * @var array
23 */
24 private $accepted_header = array(
25 'HTTP_CLIENT_IP',
26 'HTTP_X_REAL_IP',
27 'HTTP_X_FORWARDED_FOR',
28 'HTTP_X_FORWARDED',
29 'HTTP_X_CLUSTER_CLIENT_IP',
30 'HTTP_FORWARDED_FOR',
31 'HTTP_FORWARDED',
32 'HTTP_CF_CONNECTING_IP',
33 'REMOTE_ADDR',
34 );
35
36 /**
37 * Returns client IP addresses.
38 *
39 * @return array IP addresses
40 */
41 public function get_ip_address(): array {
42 $ip_list = array();
43 $server = defender_get_data_from_request( null, 's' );
44 foreach ( $this->accepted_header as $key ) {
45 if ( array_key_exists( $key, $server ) && is_string( $server[ $key ] ) && '' !== $server[ $key ] ) {
46 $ip_array = explode( ',', $server[ $key ] );
47 foreach ( $ip_array as $ip ) {
48 $ip = trim( $ip );
49 if ( $this->check_validate_ip( $ip ) ) {
50 $ip_list[] = $ip;
51 }
52 }
53 }
54 }
55
56 return $ip_list;
57 }
58
59 /**
60 * Return all the headers found.
61 *
62 * @return array Header(s) key/name.
63 */
64 public function get_ip_header(): array {
65 $header_array = array();
66 $server = defender_get_data_from_request( null, 's' );
67 foreach ( $this->accepted_header as $key ) {
68 if ( array_key_exists( $key, $server ) && is_string( $server[ $key ] ) && '' !== $server[ $key ] ) {
69 $ip_array = explode( ',', $server[ $key ] );
70 foreach ( $ip_array as $ip ) {
71 $ip = trim( $ip );
72 if ( $this->check_validate_ip( $ip ) ) {
73 $header_array[] = $key;
74 break;
75 }
76 }
77 }
78 }
79
80 return $header_array;
81 }
82 }
83