PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / htaccess-capability-tester / src / Testers / PassInfoFromRewriteToScriptThroughEnvTester.php

PassInfoFromRewriteToScriptThroughEnvTester.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/rosell-dk/htaccess-capability-tester/src/Testers/PassInfoFromRewriteToScriptThroughEnvTester.php

82 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace HtaccessCapabilityTester\Testers;
4
5 /**
6 * Class for testing if an environment variable can be set in a rewrite rule and received in PHP.
7 *
8 * @package HtaccessCapabilityTester
9 * @author Bjørn Rosell <[email protected]>
10 * @since Class available since 0.7
11 */
12 class PassInfoFromRewriteToScriptThroughEnvTester extends CustomTester
13 {
14
15 /**
16 * Constructor.
17 *
18 * @return void
19 */
20 public function __construct()
21 {
22 $htaccessFile = <<<'EOD'
23 <IfModule mod_rewrite.c>
24
25 # Testing if we can pass environment variable from .htaccess to script in a RewriteRule
26 # We pass document root, because that can easily be checked by the script
27
28 RewriteEngine On
29 RewriteRule ^test\.php$ - [E=PASSTHROUGHENV:%{DOCUMENT_ROOT},L]
30
31 </IfModule>
32 EOD;
33
34 $phpFile = <<<'EOD'
35 <?php
36
37 /**
38 * Get environment variable set with mod_rewrite module
39 * Return false if the environment variable isn't found
40 */
41 function getEnvPassedInRewriteRule($envName) {
42 // Environment variables passed through the REWRITE module have "REWRITE_" as a prefix
43 // (in Apache, not Litespeed, if I recall correctly).
44 // Multiple iterations causes multiple REWRITE_ prefixes, and we get many environment variables set.
45 // We simply look for an environment variable that ends with what we are looking for.
46 // (so make sure to make it unique)
47 $len = strlen($envName);
48 foreach ($_SERVER as $key => $item) {
49 if (substr($key, -$len) == $envName) {
50 return $item;
51 }
52 }
53 return false;
54 }
55
56 $result = getEnvPassedInRewriteRule('PASSTHROUGHENV');
57 if ($result === false) {
58 echo '0';
59 exit;
60 }
61 echo ($result == $_SERVER['DOCUMENT_ROOT'] ? '1' : '0');
62 EOD;
63
64 $test = [
65 'subdir' => 'pass-info-from-rewrite-to-script-through-env',
66 'files' => [
67 ['.htaccess', $htaccessFile],
68 ['test.php', $phpFile],
69 ],
70 'request' => 'test.php',
71 'interpretation' => [
72 ['success', 'body', 'equals', '1'],
73 ['failure', 'body', 'equals', '0'],
74 ['inconclusive', 'body', 'begins-with', '<' . '?php'],
75 ['inconclusive']
76 ]
77 ];
78
79 parent::__construct($test);
80 }
81 }
82