PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.8.0
WP 2FA – Two-factor authentication for WordPress v2.8.0
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 1 year ago class-date-time-utils.php 1 year ago class-debugging.php 1 year ago class-generate-modal.php 1 year ago class-migration.php 1 year ago class-request-utils.php 1 year ago class-settings-utils.php 1 year ago class-user-utils.php 1 year ago class-white-label.php 1 year ago index.php 1 year ago
class-request-utils.php
72 lines
1 <?php
2 /**
3 * Responsible for the requests.
4 *
5 * @package wp2fa
6 * @subpackage utils
7 * @copyright 2024 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() {
35 foreach (
36 array(
37 'HTTP_CLIENT_IP',
38 'HTTP_X_FORWARDED_FOR',
39 'HTTP_X_FORWARDED',
40 'HTTP_X_CLUSTER_CLIENT_IP',
41 'HTTP_FORWARDED_FOR',
42 'HTTP_FORWARDED',
43 'REMOTE_ADDR',
44 ) as $key
45 ) {
46 if ( array_key_exists( $key, $_SERVER ) === true ) {
47 foreach ( array_map( 'trim', explode( ',', $_SERVER[ $key ] ) ) as $ip ) { // phpcs:ignore
48 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
49 return $ip;
50 }
51 }
52 }
53 }
54 }
55
56 /**
57 * Extracts the User agent for the currently request.
58 *
59 * @return string
60 *
61 * @since 2.0.0
62 */
63 public static function get_user_agent() {
64 if ( ! array_key_exists( 'HTTP_USER_AGENT', $_SERVER ) ) {
65 return '';
66 }
67
68 return trim( (string) $_SERVER['HTTP_USER_AGENT'] ); // phpcs:ignore
69 }
70 }
71 }
72