Cloudflare: cURL header get blocked

2.1k Views Asked by At

I have the problem that cloudflare (PRO = Paid) blocked my php cURL to get header information. I am owner of that site and i have whitelisted my own server-ips.

Here are the code, all other website without CF works less problems:

<?php 
$url = "https://domain.tld";

$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_HEADER, true); // we want headers 
curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_TIMEOUT,10); 
$output = curl_exec($ch); 
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
curl_close($ch);

echo 'HTTP code: ' . $httpcode; 
?>

What can i do there?

Thanks

1

There are 1 best solutions below

2
On

In the Cloudflare dashboard, click on the Firewall tab - you can then whitelist IPs in the Access Control window:

Cloudflare IP Firewall

Note that you need to whitelist the IP which is making the cURL request itself.

For more information, please see: How do I control access to my site?

Let us know if you still face issues after setting that up.