PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.1.0
WP 2FA – Two-factor authentication for WordPress v2.1.0
1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / Utils / RequestUtils.php
wp-2fa / includes / classes / Utils Last commit date
AbstractMigration.php 4 years ago DateTimeUtils.php 4 years ago Debugging.php 5 years ago GenerateModal.php 4 years ago Migration.php 4 years ago RequestUtils.php 4 years ago SettingsUtils.php 4 years ago UserUtils.php 4 years ago index.php 5 years ago
RequestUtils.php
57 lines
1 <?php
2
3 namespace WP2FA\Utils;
4
5 /**
6 * Utility class to extract info from current request.
7 *
8 * @package WP2FA\Utils
9 * @since 2.0.0
10 */
11 class RequestUtils {
12
13 /**
14 * Extracts the IP address for the currently browsing user
15 *
16 * @return string
17 *
18 * @since 2.0.0
19 */
20 public static function get_ip() {
21 foreach (
22 array(
23 'HTTP_CLIENT_IP',
24 'HTTP_X_FORWARDED_FOR',
25 'HTTP_X_FORWARDED',
26 'HTTP_X_CLUSTER_CLIENT_IP',
27 'HTTP_FORWARDED_FOR',
28 'HTTP_FORWARDED',
29 'REMOTE_ADDR'
30 ) as $key
31 ) {
32 if ( array_key_exists( $key, $_SERVER ) === true ) {
33 foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] ) ) as $ip ) { // @codingStandardsIgnoreLine
34 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
35 return $ip;
36 }
37 }
38 }
39 }
40 }
41
42 /**
43 * Extracts the User agent for the currently request.
44 *
45 * @return string
46 *
47 * @since 2.0.0
48 */
49 public static function get_user_agent() {
50 if ( ! array_key_exists( 'HTTP_USER_AGENT', $_SERVER ) ) {
51 return '';
52 }
53
54 return trim( $_SERVER['HTTP_USER_AGENT'] );
55 }
56 }
57