RumbleFrog icon

Image Proxy

RumbleFrog | PRO | 01/28/17 03:30:49 PM UTC | 0 ⭐ | 362 👁️ | Never ⏰ | []
PHP |

1.31 KB

|

None

|

0 👍

/

0 👎

<?php
 
class Proxy {
    protected $allowed = [];
 
    public function __construct()
    {
 
        if(!isset($_GET['url'])) {
            header("HTTP/1.0 404 Not Found");
            die('404 - 1');
        }
        
 
        if (filter_var($_GET['url'], FILTER_VALIDATE_URL) === false) {
            header("HTTP/1.0 404 Not Found");
            die('404 -2');
        }
 
        if(!$this->isAllowed($_GET['url'])) {
            header("HTTP/1.0 404 Not Found");
            die('404 - 3');
        }
    }
 
    public function output()
    {
        $ext = pathinfo($this->url, PATHINFO_EXTENSION);
        switch ($ext) {
        case "gif":
            header('Content-Type: image/gif');
            readfile($this->url);
            break;
        case "png":
            header('Content-Type: image/png');
            readfile($this->url);
            break;
        case "jpg":
        default:
            header('Content-Type: image/jpeg');
            readfile($this->url);
            break;
        }
    }
 
    protected function getHost()
    {
        $result = parse_url($this->url);
        return $result['host'];
    }
 
    protected function isAllowed($url)
    {
        return in_array($this->getHost($url), $this->allowed);
    }
}
 
(new Proxy)->output();

Comments