Created
December 11, 2017 17:25
-
-
Save milnerm/2877e2f1e950e0da631edd568880e0ba to your computer and use it in GitHub Desktop.
Basic cURL PHP http to local https pass through
This file contains 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 if(!empty($_GET['httpurl'])){ | |
/** | |
* Basic cURL script for passing http through https locally, to get around mixed-security issues in browsers | |
* not fully tested; can handle GET and POST data as needed. | |
* $_GET['httpurl'] is urlencoded | |
*/ | |
$cookie = tmpfile(); | |
$userAgent = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31'; | |
$thisurl=urldecode($_GET['httpurl']); | |
//basic check for domain | |
$domain=explode('?',$thisurl); | |
$passthrough = curl_init(); | |
//url-ify the data for the POST | |
if($_POST){ | |
foreach($_POST as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } | |
rtrim($fields_string, '&'); | |
curl_setopt($passthrough, CURLOPT_URL, $thisurl); | |
curl_setopt($passthrough, CURLOPT_POST, count($fields)); | |
curl_setopt($passthrough, CURLOPT_POSTFIELDS, $fields_string); | |
}else{ | |
unset($_GET['httpurl']); | |
foreach($_GET as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } | |
rtrim($fields_string, '&'); | |
curl_setopt($passthrough, CURLOPT_URL, $domain[0].'?'.$fields_string); | |
} | |
curl_setopt($passthrough, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($passthrough, CURLOPT_AUTOREFERER, true); | |
curl_setopt($passthrough, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($passthrough, CURLOPT_USERAGENT, $userAgent); | |
curl_setopt($passthrough, CURLOPT_COOKIEFILE, $cookie); | |
$passthroughdata=curl_exec($passthrough); | |
curl_close($cced); | |
header("Content-Type: ".$_SERVER["CONTENT_TYPE"]."; charset=utf-8"); | |
//not pretty, but it works. Need to sort out relative paths | |
$passthroughdata=str_ireplace('src="/','src="'.$domain[0],$passthroughdata); | |
$passthroughdata=str_ireplace('href="/','href="'.$domain[0],$passthroughdata); | |
$passthroughdata=str_ireplace("src='/","src='".$domain[0],$passthroughdata); | |
$passthroughdata=str_ireplace("href='/","href='".$domain[0],$passthroughdata); | |
print $passthroughdata; | |
}?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment