How to emulate php CURL request on server? CURL request blocked from server but not from localhost

435 views Asked by At

I wrote a script to request information from a remote website. I debugged everything locally and deployed to server.

Everything run smoothly on my localhost until I loaded to the server where the curl_execute wasn't able to connect to the target host. I debugged with another URL and it worked so I guess there is no configurations needed from the server side. I am guessing the target host denies or something a response to the request - I just don't know how nor why.

This is the code I use to make the request.

ch = curl_init();
    $http_headers = array(
                    'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
                    'Connection: keep-alive',
                    'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124'
                  );

    curl_setopt($ch, CURLOPT_URL, $targetURL);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    curl_close($ch);

What can I do to emulate a 'normal' request and avoid being denied by the target host? Any tips, appreciated.

Regards

0

There are 0 answers