Curl error: Warning: curl_exec (): 45 is not a valid cURL handle resource

I tried to extract data from a google search. I used the code below

$curl = curl_init();   
curl_setopt ($curl, CURLOPT_URL, "http://www.google.com/search?output=toolbar&q=".urlencode($fkey));  
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);  
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);  
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);  
$contentstring = curl_exec ($curl);
curl_close ($curl);
print $contentstring; 


But its not displaying the page as below

enter image description here


Please help me solve this problem ... Thanks in advance

+3
source share
2 answers

Your code works very well.

As you can see the image. Google blocked the request from your IP address because it detected unusual traffic activity.

You can always check the HTTP status code that your requesting URL gives.

echo $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

If everything is fine, you will receive a response 200, otherwise you will receive a different status code.

Here are the most common HTTP status codes.

enter image description here

+2
source

:

echo curl_error($curl) . ' (' . curl_errno($curl) . ')';
curl_close($curl);
0

All Articles