Created
December 20, 2015 15:56
-
-
Save TechNinjaWeb/2e4afbc80c7eb9f89205 to your computer and use it in GitHub Desktop.
PHP Curl Request Response
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 | |
header('Content-type: text/html'); | |
header('Access-Control-Allow-Origin: *'); | |
$string = parse_str($_SERVER["QUERY_STRING"]); | |
$curl = curl_init(); | |
$timeout = 30; | |
$ret = ""; | |
if ($_REQUEST["data"]) { | |
$data = $_REQUEST["data"]; | |
} | |
if ($data) { | |
$url = utf8_decode(urldecode($data)); | |
} else if ($_POST["data"]) { | |
$url = utf8_decode(urldecode($_POST["data"])); | |
} | |
$options = Array( | |
CURLOPT_URL => $url, | |
CURLOPT_FOLLOWLOCATION => 1, | |
CURLOPT_MAXREDIRS => 20, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5", | |
CURLOPT_CONNECTTIMEOUT => $timeout, | |
CURLOPT_RETURNTRANSFER => 1 | |
); | |
curl_setopt_array($curl, $options); | |
$response = curl_exec($curl); | |
?> | |
<?php | |
curl_close($curl); | |
echo $response; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment