[FIXED] Getting curl response from CLI but access denied from PHP


For many requests I am getting access denied errors when using curl from php, my code is:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
    curl_setopt($ch, CURLOPT_URL, 'https://www.vueling.com/en');
    curl_setopt($ch, CURLOPT_TIMEOUT, '2');
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    $data = curl_exec($ch);
    echo $data;

which returns this:

<H1>Access Denied</H1>

However if I run it directly on the command line:

curl -v https://www.vueling.com/en

I get the full response, my ip is not blocked, im not sure why CLI works but PHP doesnt? Anyone have any ideas?


The CLI version of curl probably sends an user agent that is accepted by this website, but the PHP version of curl may send an user agent that is rejected.

So you have to check that the headers sent by curl are similar in both ways.

Answered By – A.L

Answer Checked By – David Marino (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published