php - Retrieve a file from a URL and serve it with the same headers -


currently i'm working on building smf mod enables ssl , 1 thing keeps poping issue of user embedded content (like images) , other sorts of things not being served sites ssl. i'm after way build sort of proxy script run on site , when passed url, retrieve file, maintain of headers (eg. mime type) , serve file again. way looks image or whatever being served ssl enabled site when infact not.

thanks comments! want in future, heres script i'm using:

<?php     $requesturl = filter_var($_request["url"], filter_sanitize_url);     if(filter_var($requesturl, filter_validate_url, filter_flag_path_required))     {         if(isset($_server['http_if_modified_since']))         {             // load headers destination server.             $uri_info = new uriinfo($requesturl);             if($uri_info->info['filetime'] == strtotime($_server['http_if_modified_since']))             {                 header('http/1.1 304 not modified');             }             else             {                 //serve new copy of file, changed :o                 $ch = curl_init();                 curl_setopt($ch, curlopt_url, $requesturl);                 curl_setopt($ch, curlopt_header, 0);                 curl_setopt($ch, curlopt_filetime, 1);                 curl_setopt($ch, curlopt_followlocation, 1);                 curl_setopt($ch, curlopt_returntransfer, 1);                 curl_setopt($ch, curlopt_binarytransfer, 1);                 $data = curl_exec($ch);                 $info = curl_getinfo($ch);                 curl_close($ch);                  //display image in browser                 header('content-type: ' . $info['content_type']);                 header('last-modified: ' . gmdate('d, d m y h:i:s \g\m\t', $info['filetime']));                 header('cache-control: no-cache'); //stop cloudflare!                 echo $data;             }         }         else         {             //just serve file, don't have copy of it!             $ch = curl_init();             curl_setopt($ch, curlopt_url, $requesturl);             curl_setopt($ch, curlopt_header, 0);             curl_setopt($ch, curlopt_filetime, 1);             curl_setopt($ch, curlopt_followlocation, 1);             curl_setopt($ch, curlopt_returntransfer, 1);             curl_setopt($ch, curlopt_binarytransfer, 1);             $data = curl_exec($ch);             $info = curl_getinfo($ch);             curl_close($ch);              //display image in browser             header('content-type: ' . $info['content_type']);             header('last-modified: ' . gmdate('d, d m y h:i:s \g\m\t', $info['filetime']));             header('cache-control: no-cache'); //stop cloudflare!             echo $data;         }     }         exit(); ?>     <?php      class uriinfo      {         public $info;         public $header;         private $url;          public function __construct($url)         {             $this->url = $url;             $this->setdata();         }          public function setdata()          {             $curl = curl_init();             curl_setopt($curl, curlopt_url, $this->url);             curl_setopt($curl, curlopt_filetime, 1);             curl_setopt($curl, curlopt_followlocation, 1);             curl_setopt($curl, curlopt_nobody, 1);             curl_setopt($curl, curlopt_returntransfer, 1);             $this->header = curl_exec($curl);             $this->info = curl_getinfo($curl);             curl_close($curl);         }          public function getfiletime()          {             return $this->info['filetime'];         }     }  ?> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -