Saturday, 17 August 2013

cURL cookie workout failure

cURL cookie workout failure

I want to get some data from a web page thru Curl. Yet, the reply i got is
that turn on your brouser's setting tosupport cookie. I followed a native
php tutorial but no avail. Here is the code, could you say what's wrong or
missing?
<?php
session_start();
$strCookie = '';
session_write_close();
$url = 'http://cars.auto.com/list/...';
$curl_handle = curl_init($url);
curl_setopt($curl_handle, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Googlebot/2.1
(+http://www.google.com/bot.html)');
curl_setopt($curl_handle, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt( $curl_handle, CURLOPT_COOKIE, $strCookie );
curl_setopt($curl_handle, CURLOPT_COOKIEJAR, dirname(__FILE__).
'cookie.txt'); dirname(__FILE__).
curl_setopt($curl_handle, CURLOPT_COOKIEFILE, dirname(__FILE__).
'cookie.txt');
curl_setopt( CURLOPT_FILE, '/dev/null');
// EXECUTE 1st REQUEST
$store = curl_exec ($curl_handle);
// SET for second request
curl_setopt($curl_handle, CURLOPT_URL,
'http://cars.auto.com/cars/used/sale/44507490-3f21.html');
// EXECUTE 2nd REQUEST
$content = curl_exec ($curl_handle);
// CLOSE CURL
curl_close ($curl_handle);
echo $content;
?>

No comments:

Post a Comment