Answers for "php curl -u"

PHP
3

php curl get

PHP cURL GET Request
A GET request retrieves data from a server. This can be a website’s HTML, an API response or other resources.

<?php

$cURLConnection = curl_init();

curl_setopt($cURLConnection, CURLOPT_URL, 'https://hostname.tld/phone-list');
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);

$phoneList = curl_exec($cURLConnection);
curl_close($cURLConnection);

$jsonArrayResponse - json_decode($phoneList);
Posted by: Guest on April-04-2020
8

php curl

// set post fields
$post = [
    'username' => 'user1',
    'password' => 'passuser1',
    'gender'   => 1,
];

$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
$response = curl_exec($ch);

// close the connection, release resources used
curl_close($ch);

// do anything you want with your response
var_dump($response);
Posted by: Guest on May-15-2020
1

php curl example

function getUrl($url){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
}
Posted by: Guest on June-26-2019
2

php curl

// The ultimate function for all php curl requests all in one
function curl( $api_url,$request = 'get' , $params = array() , $mode = false , $timeout='')
{
    $request = strtolower($request);

    $ch = curl_init($api_url);

    if($request == 'post')
    {
        curl_setopt ($ch, CURLOPT_POST, TRUE);
        curl_setopt ($ch, CURLOPT_POSTFIELDS, http_build_query($params));
    }
    
    if( $timeout != ''  )
    {
        curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
    }

    if($request == 'put')
    {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    }
  
    if($request == 'delete')
    {
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    }

    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

    $response     = curl_exec($ch);

    if($mode)
        $response     = json_decode($response , $mode);
    else
        $response     = json_decode($response);    

    return $response;
}
Posted by: Guest on July-03-2021

Browse Popular Code Answers by Language