PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.9.2
WP 2FA – Two-factor authentication for WordPress v2.9.2
4.0.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 / class-request-utils.php
wp-2fa / includes / classes / Utils Last commit date
class-abstract-migration.php 10 months ago class-date-time-utils.php 10 months ago class-debugging.php 10 months ago class-generate-modal.php 10 months ago class-migration.php 10 months ago class-request-utils.php 10 months ago class-settings-utils.php 10 months ago class-user-utils.php 10 months ago class-validator.php 10 months ago class-white-label.php 10 months ago index.php 10 months ago
class-request-utils.php
73 lines
1 <?php
2 /**
3 * Responsible for the requests.
4 *
5 * @package wp2fa
6 * @subpackage utils
7 * @copyright 2025 Melapress
8 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
9 * @link https://wordpress.org/plugins/wp-2fa/
10 * @since 2.0.0
11 */
12
13 declare(strict_types=1);
14
15 namespace WP2FA\Utils;
16
17 if ( ! class_exists( '\WP2FA\Utils\Request_Utils' ) ) {
18
19 /**
20 * Utility class to extract info from current request.
21 *
22 * @package WP2FA\Utils
23 * @since 2.0.0
24 */
25 class Request_Utils {
26
27 /**
28 * Extracts the IP address for the currently browsing user
29 *
30 * @return string
31 *
32 * @since 2.0.0
33 */
34 public static function get_ip(): string {
35 $ip_address = '';
36
37 foreach (
38 array(
39 'HTTP_CLIENT_IP',
40 'HTTP_X_FORWARDED_FOR',
41 'HTTP_X_FORWARDED',
42 'HTTP_X_CLUSTER_CLIENT_IP',
43 'HTTP_FORWARDED_FOR',
44 'HTTP_FORWARDED',
45 'REMOTE_ADDR',
46 ) as $key
47 ) {
48 if ( array_key_exists( $key, $_SERVER ) ) {
49 foreach ( array_map( 'trim', explode( ',', \wp_unslash( $_SERVER[ $key ] ) ) ) as $ip ) {
50 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
51 $ip_address = $ip;
52 break 2;
53 }
54 }
55 }
56 }
57
58 return $ip_address;
59 }
60
61 /**
62 * Extracts the User agent for the current request.
63 *
64 * @return string
65 *
66 * @since 2.0.0
67 */
68 public static function get_user_agent(): string {
69 return array_key_exists( 'HTTP_USER_AGENT', $_SERVER ) ? trim( (string) \sanitize_text_field( \wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) ) : '';
70 }
71 }
72 }
73