ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
reverseproxy.php
Go to the documentation of this file.
1 <?php
2 
3 // The url we're proxying to.
4 $remoteUrl = 'http://example.org/';
5 
6 // The url we're proxying from. Please note that this must be a relative url,
7 // and basically acts as the base url.
8 //
9 // If your $remoteUrl doesn't end with a slash, this one probably shouldn't
10 // either.
11 $myBaseUrl = '/reverseproxy.php';
12 // $myBaseUrl = '/~evert/sabre/http/examples/reverseproxy.php/';
13 
15 use Sabre\HTTP\Sapi;
16 
17 // Find the autoloader
18 $paths = [
19  __DIR__ . '/../vendor/autoload.php',
20  __DIR__ . '/../../../autoload.php',
21  __DIR__ . '/vendor/autoload.php',
22 
23 ];
24 
25 foreach ($paths as $path) {
26  if (file_exists($path)) {
27  include $path;
28  break;
29  }
30 }
31 
32 
33 $request = Sapi::getRequest();
34 $request->setBaseUrl($myBaseUrl);
35 
37 
38 // Removing the Host header.
39 $subRequest->removeHeader('Host');
40 
41 // Rewriting the url.
42 $subRequest->setUrl($remoteUrl . $request->getPath());
43 
44 $client = new Client();
45 
46 // Sends the HTTP request to the server
48 
49 // Sends the response back to the client that connected to the proxy.
50 Sapi::sendResponse($response);
$path
Definition: aliased.php:25
$remoteUrl
Definition: reverseproxy.php:4
$client
$subRequest
$paths
This example demonstrates the ability for clients to work asynchronously.
$myBaseUrl
foreach($paths as $path) $request
$response
A rudimentary HTTP client.
Definition: Client.php:44