Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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();
Advertisement
Add Comment
Please, Sign In to add comment