Salini L
Salini L

Reputation: 879

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

I was trying to fetch data from google search. I used the below code

$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 like below

enter image description here


Please somebody help me to solve this... Thanks in advance

Upvotes: 5

Views: 11666

Answers (2)

Indrajeet Singh
Indrajeet Singh

Reputation: 2989

Try this code:

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

Upvotes: 0

Your code is working pretty fine.

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

You can always check the HTTP Status Code what your requesting URL gives by..

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

If everything is normal , you would get a 200 response, else you will get some other status code.

Here are the most common HTTP Status Codes..

enter image description here

Upvotes: 3

Related Questions