building a 'simple' php url proxy -
i need implement simple php proxy in web application building (its flash based , destination service provider doesn't allow edits crossdomain.xml file)
can php gurus offer advice on following 2 options? also, think, not sure, need include header info well.
thanks feedback!
option1
$url = $_get['path']; readfile($path);
option2
$content .= file_get_contents($_get['path']); if ($content !== false) { echo($content); } else { // there error }
first of all, never ever ever include file based on user input. imagine happen if call script this:
http://example.com/proxy.php?path=/etc/passwd
then onto issue: kind of data proxying? if kind @ all, need detect content type content, , pass on receiving end knows it's getting. suggest using http_request2 or similar pear (see: http://pear.php.net/package/http_request2) if @ possible. if have access it, this:
// first validate request actual web address if(!preg_match("#^https?://#", $_get['path']) { header("http/1.1 404 not found"); echo "content not found, bad url!"; exit(); } // make request $req = new http_request2($_get['path']); $response = $req->send(); // output content-type header , use content-type of original file header("content-type: " . $response->getheader("content-type")); // , provide file body echo $response->getbody();
note code hasn't been tested, give starting point.
Comments
Post a Comment