Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP cURL request

function &web_curl_http($url) 
{  
   $c = curl_init();
   curl_setopt( $c , CURLOPT_URL , $url);
   curl_setopt( $c , CURLOPT_USERAGENT, "Mozilla/5.0 (Linux Centos 7;) Chrome/74.0.3729.169 Safari/537.36");
   curl_setopt( $c , CURLOPT_RETURNTRANSFER, true);
   curl_setopt( $c , CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt( $c , CURLOPT_SSL_VERIFYHOST, false);
   curl_setopt( $c , CURLOPT_TIMEOUT, 10000); // 10 sec
   $data = curl_exec($c);
   curl_close($c);
   return $data;
}
Comment

php curl request

$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => "http://www.example.com/yourscript.php",
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => array(
        'field1' => 'some date',
        'field2' => 'some other data',
    )
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
Comment

API call in PHP using cURL

// Method: POST, PUT, GET etc
// Data: array("param" => "value") ==> index.php?param=value

function CallAPI($method, $url, $data = false)
{
    $curl = curl_init();

    switch ($method)
    {
        case "POST":
            curl_setopt($curl, CURLOPT_POST, 1);

            if ($data)
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            break;
        case "PUT":
            curl_setopt($curl, CURLOPT_PUT, 1);
            break;
        default:
            if ($data)
                $url = sprintf("%s?%s", $url, http_build_query($data));
    }

    // Optional Authentication:
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, "username:password");

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($curl);

    curl_close($curl);

    return $result;
}
Comment

PREVIOUS NEXT
Code Example
Php :: php create array 
Php :: laravel send mail using outlook 
Php :: codeigniter sms send 
Php :: php delete file 
Php :: laravel run command 
Php :: require password confirm laravel 
Php :: logout all users laravel 8 
Php :: controller class does not exist laravel 
Php :: php carbon 
Php :: laravel @env 
Php :: codeigniter crud generator 
Php :: foreign key string laravel 
Php :: queue jobs in laravel 
Php :: how to run php in javascript 
Php :: create xml php 
Php :: open phpstorm from terminal 
Php :: laravel validation date time format 
Php :: auto logout when session expires laravel 
Php :: optional route parameter in laravel 
Php :: $e = array("red", "green", "blue"); echo intval($e) . "<br"; 
Php :: converting php to codeigniter 
Php :: csv import laravel 
Php :: nested array in laravel 
Php :: cpt change link 
Php :: PHP detect spam name 
Php :: run laravel envoy task 
Php :: rename image file using post id in wordpress programmatically 
Php :: sorting table row data with php 
Php :: Akkhor - School Management Admin Template download 
Php :: php send sms for aws sns sdk 2 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =