method curl documentation in bbn\X
Makes a Curl call towards a URL and returns the result as a string.
Example
$url = 'https://www.omdbapi.com/';
$param = ['t'=>'la vita è bella'];
X::hdump(X::curl($url,$param, ['POST' => false]));
// object {
// "Title":"La vita è bella",
// "Year":"1943",
// "Rated":"N/A",
// "Released":"26 May 1943",
// "Runtime":"76 min",
// "Genre":"Comedy"
// "imdbRating":"7.9",
// "imdbVotes":"50",
// "imdbID":"tt0036502",
// "Type":"movie",
// "Response":"True"
// }
function(string $url, $param = NULL, array $options = array (
'post' => 1,
))
{
$ch = curl_init();
self::$_last_curl = $ch;
$defined = array_map('strtolower', array_keys($options));
if (!in_array('returntransfer', $defined)) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
}
if (\is_object($param)) {
$param = self::toArray($param);
}
if (\defined('BBN_IS_SSL') && \defined('BBN_IS_DEV') && BBN_IS_SSL && BBN_IS_DEV) {
if (!in_array('ssl_verifypeer', $defined)) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
if (!in_array('ssl_verifyhost', $defined)) {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
//curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
$options = array_change_key_case($options, CASE_UPPER);
foreach ($options as $opt => $val) {
if (\defined('CURLOPT_'.$opt)) {
curl_setopt($ch, constant('CURLOPT_'.$opt), $val);
}
}
if ($param) {
if (!empty($options['POST'])) {
if (!in_array('url', $defined)) {
curl_setopt($ch, CURLOPT_URL, $url);
}
if (!in_array('postfields', $defined)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
}
}
elseif (!empty($options['DELETE'])) {
//die($url.'?'.http_build_query($param));
if (!in_array('url', $defined)) {
curl_setopt($ch, CURLOPT_URL, $url.'?'.http_build_query($param));
}
if (!in_array('customrequest', $defined)) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
}
}
elseif (!in_array('url', $defined)) {
curl_setopt($ch, CURLOPT_URL, $url.'?'.http_build_query($param));
}
}
else{
if (!in_array('url', $defined)) {
curl_setopt($ch, CURLOPT_URL, $url);
}
if (!empty($options['DELETE']) && !in_array('customrequest', $defined)) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
}
}
$r = curl_exec($ch);
if (!$r) {
self::log(["PROBLEME AVEC L'URL $url", curl_error($ch), curl_getinfo($ch)], 'curl');
}
return $r;
}
Makes a Curl call towards a URL and returns the result as a string. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions