GET Request using cURL
There will be times that you will need to pull out data from a web service using PHP’s GET method. In this tutorial I will be demonstrating how you can make a GET Request using cURL.
Example of GET Request:
You can test cURL in your own local server as it’s the same with using a regular form with an action.
$url = "https://website.com/api.php?action=get_data&x=1&y=2";
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
// Print the return data
Use json_decode if the return is in json format.
It’s best to put your cURL GET Request in a function if your a dealing with many get request in all parts of your website
Do you need help with a project? or have a new project in mind that you need help with?Contact Me