0

This question might be worded a big strange, but this is really throwing me off. I have a function that can read api output with cURL from a specific URL. This function is located in client.php. The function will send the custom header api_key. I want to send this cURL get request to server.php. How would I get the api_key header sent from client.php? Other question similar to this one only showed how to get the headers of the current page. I am pretty new to cURL, so please point me in the right direction.

<?php

function read_api_output($url, $request_type, $api_key, $timeout = '30')
{
    $curl = curl_init();

    curl_setopt_array($curl, [
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => $timeout,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => $request_type,
        CURLOPT_HTTPHEADER => ["cache-control: no-cache"],
        CURLOPT_HTTPHEADER, array(
            'auth_key: ' . $api_key
        ),
    ]);

    $response = curl_exec($curl);
    $err = curl_error($curl);

    curl_close($curl);

    $response = json_decode($response, true);
    return $response;
}

?>
PhoenixCMS
  • 11
  • 5

0 Answers0