Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

curl

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

like image 307
Salini L Avatar asked Oct 21 '22 13:10

Salini L


1 Answers

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

like image 89
Shankar Narayana Damodaran Avatar answered Oct 27 '22 10:10

Shankar Narayana Damodaran