This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzarza-real-ip.php
67 lines (52 loc) · 2.01 KB
/
zarza-real-ip.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
Plugin Name: Zarza Real IP
Plugin URI: https://wordpress.org/plugins/zarza-real-ip/
Description: This useful and free plugin corrects automatically the user's IP address and allows Wordpress to use the Real IP address if you're behind a proxy or load balancer like nginx, varnish and so on. It will start working as soon as you activate it. It is also compatible with CloudFlare, Incapsula and many others.
Version: 1.0.3
Author: Zarza Corp
Author URI: https://zarza.com/
License: GPL3
Copyright 2015 Zarza (website : https://zarza.com)
*/
// Make sure we don't expose any info if called directly
defined('ABSPATH') or die("I'm a plugin, not much I can do when called directly."); # From wp-load.php
$zrz_ip_headers = array(
'HTTP_CF_CONNECTING_IP', #CloudFlare
'HTTP_X_FORWARDED_FOR', #Incapsula, Cloudlayer
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_X_REAL_IP',
);
foreach($zrz_ip_headers as $z) {
if( ($_SERVER[$z] == "127.0.0.1") || !(isset($_SERVER[$z])) ) { # If some header is reporting localhost let's continue
unset($_SERVER[$z]);
continue;
}
if(!isset($zrz_ri_lock)){
if (!function_exists('filter_var')) {
if (preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/',$_SERVER[$z])){
$_SERVER['REMOTE_ADDR'] = $_SERVER[$z];
$zrz_ri_lock = 1;
continue;
}
}else{
if ( filter_var($_SERVER[$z], FILTER_VALIDATE_IP)){
$_SERVER['REMOTE_ADDR'] = $_SERVER[$z];
$zrz_ri_lock = 1;
continue;
}
}
}
}
// Fix issues with HTTPS
if (($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') || (strpos($_SERVER["HTTP_CF_VISITOR"], "https")) ) {
$_SERVER['HTTPS'] = 'on';
}
/*
ZARZA REAL IP
https://wordpress.org/plugins/zarza-real-ip/
ZARZA | A HEAD OF OUR TIME
https://zarza.com
*/