Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/vendor/cloudflare/cf-ip-rewrite/readme.md

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + # Cloudflare PHP IP Rewriting
2 +
3 + This module makes it easy for developers to add rewrite Cloudflare IP Addresses for actual end-user IP Addresses at the application layer. It is recommended to either install mod_cloudflare for Apache or use nginx rewrite rules (<https://support.cloudflare.com/hc/en-us/articles/200170706-Does-CloudFlare-have-an-IP-module-for-Nginx->) if possible.
4 +
5 + For those cases, where the IP can not be guaranteed to be rewritten by one of these alternate means, this module can be used to rewrite the IP address.
6 +
7 + ### How it works
8 + ```php
9 + $ipRewrite = new CloudFlare\IpRewrite();
10 + $is_cf = $ipRewrite->isCloudFlare();
11 + $rewritten_ip = $ipRewrite->getRewrittenIP();
12 + $original_ip = $ipRewrite->getOriginalIP();
13 + ```
14 + The class exposes three methods for interaction and a constructor.
15 +
16 + Initializing `IpRewrite()` object will try to rewrite the IP. If the IP is rewritten, `$_SERVER["REMOTE_ADDR"]` will be updated to reflect the end-user's IP address.
17 +
18 + `isCloudFlare();` returns `true` if the `CF_CONNECTING_IP` header is present in the request and the request originates from a Cloudflare IP.
19 +
20 + `getRewrittenIP()` Returns the rewritten ip address if a rewrite occurs, otherwise it will return `null`.
21 +
22 + `getOriginalIP()` returns the saved original ip address from `$_SERVER["REMOTE_ADDR"]`.
23 +
24 + ### Best Pratice
25 +
26 + ```php
27 + // Initialize object to rewrite the headers
28 + try {
29 + $ipRewrite = new CloudFlare\IpRewrite();
30 + } catch (RuntimeException $e) {
31 + // PHP configurations does not support IPv6
32 + }
33 +
34 + // Check if the request is from Cloudflare
35 + $is_cf = $ipRewrite->isCloudFlare();
36 + if ($is_cf) {
37 + // Get original or rewritten ip
38 + // Order does not matter
39 + ...
40 + $rewritten_ip = $ipRewrite->getRewrittenIP();
41 + ...
42 + $original_ip = $ipRewrite->getOriginalIP();
43 + ...
44 + }
45 + ```
46 +
47 + #### Caution
48 +
49 + Rewrite action is triggered only once in constructor. If `getRewrittenIP()` or `getOriginalIP()` is called multiple times it'll return the first result regardless if a change happened after the first call. Since rewrite action was not triggered.
50 +
51 + To get the newest changes a new `IpRewrite` object should be used.
52 +
53 + ### Testing this module
54 +
55 + This module comes with a set of tests that can be run using phpunit. To run the tests, run `composer install` on the package and then one of the following commands:
56 +
57 + #### Basic Tests
58 +
59 + composer test
60 +
61 + #### With code coverage report in `coverage` folder
62 +
63 + vendor/bin/phpunit -c phpunit.xml.dist --coverage-html coverage
64 +