PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.3
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.3
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 / PassInfoFromRewriteToScriptThroughRequestHeaderTester.php

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

66 lines 2.0 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 * Say you have a rewrite rule that points to a PHP script and you would like to pass some information
7 * along to the PHP. Usually, you will just pass it in the query string. But this won't do if the information
8 * is sensitive. In that case, there are some tricks available. The trick being tested here sets tells the
9 * RewriteRule directive to set an environment variable which a RequestHeader directive picks up on and passes
10 * on to the script in a request header.
11 *
12 * @package HtaccessCapabilityTester
13 * @author Bjørn Rosell <[email protected]>
14 * @since Class available since 0.7
15 */
16 class PassInfoFromRewriteToScriptThroughRequestHeaderTester extends CustomTester
17 {
18
19 /**
20 * Constructor.
21 *
22 * @return void
23 */
24 public function __construct()
25 {
26 $htaccessFile = <<<'EOD'
27 <IfModule mod_rewrite.c>
28 RewriteEngine On
29 # We pass document root, because that can easily be checked by the script
30 RewriteRule ^test\.php$ - [E=PASSTHROUGHHEADER:%{DOCUMENT_ROOT},L]
31
32 <IfModule mod_headers.c>
33 RequestHeader set PASSTHROUGHHEADER "%{PASSTHROUGHHEADER}e" env=PASSTHROUGHHEADER
34 </IfModule>
35
36 </IfModule>
37 EOD;
38
39 $phpFile = <<<'EOD'
40 <?php
41 if (isset($_SERVER['HTTP_PASSTHROUGHHEADER'])) {
42 echo ($_SERVER['HTTP_PASSTHROUGHHEADER'] == $_SERVER['DOCUMENT_ROOT'] ? 1 : 0);
43 exit;
44 }
45 echo '0';
46 EOD;
47
48 $test = [
49 'subdir' => 'pass-info-from-rewrite-to-script-through-request-header',
50 'files' => [
51 ['.htaccess', $htaccessFile],
52 ['test.php', $phpFile],
53 ],
54 'request' => 'test.php',
55 'interpretation' => [
56 ['success', 'body', 'equals', '1'],
57 ['failure', 'body', 'equals', '0'],
58 ['inconclusive', 'body', 'begins-with', '<' . '?php'],
59 ['inconclusive']
60 ]
61 ];
62
63 parent::__construct($test);
64 }
65 }
66