cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

cookiejar problem

From: <theexperts_at_allprodirect.com>
Date: Mon, 11 Mar 2002 03:22:00 -0500

Can anyone explain why the cookies are not working for this script? I
couldn't find much documentation on how to implement cookies in cURL. Am I
doing something wrong?

function sendtohost($url,$data,$post) {
    $referer = $url;
    $useragent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)';
    $cookiefile = '/myfilepath/cookies.txt';
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_REFERER, $referer);
    curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
    curl_setopt ($ch, CURLOPT_POST, $post);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_HEADER, 1);
    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookiefile);
    curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookiefile);
    curl_setopt ($ch, CURLOPT_VERBOSE, 1);
    $result = curl_exec ($ch);
    curl_close ($ch);
    return $result;
}

Background info: I need to access 4 sites from my server script. The scipt
works fine for 2 of them. I figured out that the other 2 sites require
cookie transactions. They will not work even from a browser without cookies
enabled. With cookies disabled, Internet Explorer just follows the suggested
link back to the home page.

A Netscape cookie file with the required cookies was created by browsing to
the sites in Netscape 6.2. This file was then uploaded. The path to the
cookie file is correct since the script can read the file. Full file
permissions have been tried. My script still gets a response like the
following:

HTTP/1.1 100 Continue Server: Microsoft-IIS/4.0 Date: Mon, 11 Mar 2002
09:54:14 GMT HTTP/1.1 302 Object Moved Location: /index.cfm Server:
Microsoft-IIS/4.0 Content-Type: text/html Content-Length: 153 ...etc.

Strangely, cURL is silent even with VERBOSE set. Also, there are no errors
(curl_errno == 0; curl_error == ''). Maybe curl is having a problem writing
to the file? But then wouldn't there be an error? My server is running:
Apache/1.3.3 (Unix) PHP/4.1.2 libcurl 7.9.3 (OpenSSL 0.9.5)

Thanks in advance for any help!!!
Received on 2002-03-11