Joseph
Joseph

Reputation: 314

PHP cURL grab_page("") not working for some websites

First of all I am not defending GoDaddy in anyway.

Just because you want a country blocked doesn't mean everybody does. I used to develop games and had games that made money from those countries. Most of those hack attempts can mimic users. Some bots are wanted because they crawl your sites to help you show on search engines.

Upvotes: 0

Views: 368

Answers (1)

EvE
EvE

Reputation: 750

curl does not always have up to date root SSL certificates like your browser does. Add the following option to succeed.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

The code for the grab_page function then becomes.

function grab_page($site)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_URL, $site);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    return curl_exec($ch);
}

echo grab_page("https://effect.ai/");

Upvotes: 2

Related Questions