PHP Curl Get Request with Parameters Example

By Hardik Savani May 14, 2024 Category : PHP

This simple article demonstrates of php curl get request with parameters example. This article goes in detailed on php curl get request example. it's simple example of php curl get request with params. it's simple example of curl get request php example. Let's get started with curl http request php.

In this tutorial, i will give you very simple example of how to send get curl request with parameters in php. so, let's see bellow example with output:

Example:

<?php

$ch = curl_init();

$url = "https://api.mywebtuts.com/api/users";

$dataArray = ['page' => 2];

$data = http_build_query($dataArray);

$getUrl = $url."?".$data;

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_URL, $getUrl);

curl_setopt($ch, CURLOPT_TIMEOUT, 80);

$response = curl_exec($ch);

if(curl_error($ch)){

echo 'Request Error:' . curl_error($ch);

}else{

echo $response;

}

curl_close($ch);

?>

Output:

i hope it can help you...

Tags :
Shares