![]() (I’ve updated this function so we’ll be able to define the headers when we’re making the call. Make sure to put this code into a file or place that can be accessed by your entire app or website. This is why I’ve created a ‘simple’ PHP script that allows us to call this function, with a set of parameters, and a cURL request will be done. Implementing an external API into your project is probably going to take more than just one API call and from different pages in your project. If you’re looking for a simple cURL GET function to retrieve your API data with PHP, please check if my basic cURL API connection with PHP is a better fit for your needs. Now that we understand the basics, let’s try to put this into a function we can reuse within our application. So after we did our call and closed the connection, we can still access the result using our $output variable. This $output variable is still available in our program even after we closed it with curl_close(). Note that we stored our curl_exec() in a variable $output. (deletes the variable made by curl_init) close curl resource to free up system resources curl_exec() executes the started curl session return the transfer as a string, also with setopt()Ĭurl_setopt($curl, CURLOPT_RETURNTRANSFER, 1) create
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |