2

I want to know how I can make a curl-request in php with a URL including parameters ex.:

URL.tld/test.php?paramenter=test

The curl-request just must request an http visit of that URL and then close again.

Thank you in advance.

1
  • 2
    Can you show the code that you tried with? Is there any error message? Commented Oct 4, 2019 at 4:37

1 Answer 1

2

Get request for example:

<?php

$query = http_build_query([
 'param1' => 'value1',
 'param2' => 'value2',
]);

$url = "http://example.com/?".$query;

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "cache-control: no-cache"
  ),
));

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

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Great start @hNczy.
Thank you, I will them I try this evening :)
@AndyK. select the answer and up-vote if you get your solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.