Created
May 20, 2019 14:07
-
-
Save alpenzoo/c004eef71ce368e4fa2b56f3217eb6cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // PHP Simple Proxy | |
| // Responds to GET or POST | |
| //I would use session or other checks to prevent abuse. | |
| //do not put it in the wild without limiting usage to a domain, list of urls etc | |
| $url = ($_POST['url']) ? $_POST['url'] : $_GET['url']; | |
| $url = urldecode($url); | |
| if(empty($url)){ | |
| echo "nothing to download"; | |
| exit; | |
| } | |
| $filename = ($_POST['filename']) ? $_POST['filename'] : $_GET['filename']; | |
| //start cURL session | |
| $session = curl_init($url); | |
| // Put the POST data in the body, if needed | |
| if ($_POST['url']) { | |
| $postvars = ''; | |
| while ($element = current($_POST)) { | |
| $postvars .= key($_POST).'='.$element.'&'; | |
| next($_POST); | |
| } | |
| curl_setopt ($session, CURLOPT_POST, true); | |
| curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars); | |
| } | |
| curl_setopt($session, CURLOPT_HEADER, false); | |
| curl_setopt($session, CURLOPT_FOLLOWLOCATION, true); | |
| //curl_setopt($ch, CURLOPT_TIMEOUT, 4); | |
| curl_setopt($session, CURLOPT_RETURNTRANSFER, true); | |
| // Make the call | |
| $response = curl_exec($session); | |
| curl_close($session); | |
| $mimeType = ''; | |
| //if you need try detect mime and add back to response | |
| if ($mimeType != ""){ | |
| header("Content-Type: ".$mimeType); | |
| } | |
| if(!empty($filename)){ | |
| header('Content-Disposition: attachment; filename="'.$filename.'"'); | |
| } | |
| echo $response; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment