proxy.php

Simple redirection proxy
git clone git://git.finwo.net/misc/proxy.php
Log | Files | Refs | README

index.php (1067B)


      1 <?php
      2 
      3 // Start autoloader
      4 require_once(__DIR__.'/../vendor/autoload.php');
      5 
      6 // Useful tool
      7 $accessor = new \Finwo\PropertyAccessor\PropertyAccessor();
      8 
      9 // Fetch what we're hosting
     10 $domain         = \Finwo\Request::domain();
     11 $config         = require(__DIR__.'/../config/index.php');
     12 $domainSettings = $accessor->getSafe($config, sprintf('domains|%s', $domain));
     13 
     14 $headers = \Finwo\Request::headers();
     15 $url     = http_build_url(array_merge(parse_url(\Finwo\Request::fulluri()), $domainSettings));
     16 
     17 unset($headers['Host']);
     18 unset($headers['Cookie']);
     19 
     20 // Pre-process the headers
     21 foreach ($headers as $name => &$header) {
     22     $header = sprintf("%s: %s", $name, $header);
     23 }
     24 
     25 // Make request
     26 $rawResult = \Finwo\Request::transmit($url, array(
     27     'headers' => $headers
     28 ));
     29 
     30 // 'Parse' result
     31 $result        = explode("\r\n\r\n", $rawResult, 2);
     32 $resultHeaders = explode("\r\n",array_shift($result));
     33 $resultBody    = array_shift($result);
     34 
     35 // Transmit headers
     36 foreach ($resultHeaders as $resultHeader) {
     37     header($resultHeader);
     38 }
     39 
     40 // Transmit body
     41 print($resultBody);