Skip to content

Instantly share code, notes, and snippets.

@radityopw

radityopw/curl.php

Last active Sep 2, 2017
Embed
What would you like to do?
<?php
$cURL = curl_init();
$User_Agent = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31';
$cookies = 'CookieName1=Value;CookieName2=Value';
curl_setopt($cURL, CURLOPT_USERAGENT, $User_Agent);
curl_setopt($cURL, CURLOPT_COOKIE, $cookies);
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HTTPGET, true);
if($debug){
curl_setopt($cURL, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'w+');
curl_setopt($cURL, CURLOPT_STDERR, $verbose);
}
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
//curl_exec($cURL);
$result = curl_exec($cURL);
if ($result === FALSE && $debug) {
printf("cUrl error (#%d): %s<br>\n", curl_errno($cURL),
htmlspecialchars(curl_error($cURL)));
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
}
curl_close($cURL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.