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

curl-and-php

RE: Curl cookie problem

From: David Raasch <infoiwant_at_frontierblazers.com>
Date: Wed, 25 Feb 2004 13:45:52 -0600

Well, for anyone who cares, I commented out all libcurl lines and instead
substituted shell_exec calls to command-line curl. Doing so, I managed to
replicate the problem.

For some reason, when curl looks at the headers being passed to it from this
one-site-out-of-five, it must error out or not see the cookies inside it or
something. I even forced curl to write out the headers in the exact
location of my cookie file, figuring the next curl request was set to read
that file. It didn't. Or at least it didn't act upon the cookies therein.

My site, where this is running fine, is running libcurl 7.10.8.

The site with the problems is running 7.10.5.

I figure that difference must account for the problem.

I checked the changelog but nothing sticks out as being the cause of the
problem. But then, a lot of that stuff is Greek to me.

Thanks!

-= Dave =-

-----Original Message-----
From: curl-and-php-bounces_at_cool.haxx.se
[mailto:curl-and-php-bounces_at_cool.haxx.se] On Behalf Of David Raasch
Sent: Tuesday, February 24, 2004 4:43 PM
To: curl-and-php_at_cool.haxx.se
Subject: Curl cookie problem

Greetings All !
 
I've got a piece of code that has been working fine on a particular site I
own for a few weeks now.

The piece in question basically is a loop. Basically, we take five similar
websites and process through each of them in this loop.

Curl is used to make a request to pull up the site's login page. At this
point, the site tries to set a cookie in a browser, so curl is set to
capture that cookie a la setopt_cookiejar. Curl then makes a second
request, passing login information to the form-processing script on the
destination site. The destination site apparently looks to see if that
cookie's been set. The second request then gives us some output we don't
really need... but this completes the log-in sequence.

After this, we make some other requests to pull in data.

When those are complete, the loop starts over with site #2, and so on.

Now, this has been working fine on MY site for a few weeks.

Late last week, I moved copy of this script over to somebody ELSE'S site on
a different server. Here, the script processes through ALL of the websites
we ask it to log into EXCEPT one!! My troubleshooting has determined that
the cookie file is NOT getting written to! And I cannot understand WHY.

I tried cutting-and-pasting the large chunk of code from my site into this
other site's copy of the script.... just in case I somehow deleted a
character or something earlier.... but the problem remains the same!

I don't get it. What could possibly be keeping us from writing that cookie
file?

The loop of code starts something like this.

                // manually create the cookie file with a unique identifier
                $starttime=getmicrotime();
        
$mycookiefile="/home/cookies/".$username."_".$starttime.".txt";
                echo "mycookiefile= $mycookiefile <BR>";
                $fp = fopen("$mycookiefile","w") or die("<BR><B>Unable to
open cookie file $mycookiefile for write!<BR>");
                // I stuck this in in one of my troubleshooting attempts,
thinking it was a file permissions problem
                chmod("$mycookiefile", 0777);
                fclose($fp);

                $fh = fopen("/home/davez_curl_log.txt",'w') or die("Unable
to open davez_curl_log.txt file<BR>");
                $ch= curl_init();
                $LOGINURL=$SITE_LOGIN_PAGE_URL;
                echo "LOGINURL=$LOGINURL</B><BR>";
                curl_setopt($ch, CURLOPT_URL,$LOGINURL);
                curl_setopt($ch, CURLOPT_VERBOSE, 1);
                curl_setopt($ch, CURLOPT_HEADER,1); // return header with
output
                curl_setopt($ch, CURLOPT_COOKIEJAR, "$mycookiefile");
                curl_setopt($ch, CURLOPT_STDERR, $fh);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                $result = curl_exec($ch);
                
                // here I shoved a few things that I thought might help me
debug the problem.
                echo "<BR></BR>";
                echo curl_error($ch);
                print_r(curl_getinfo($ch));
                echo "<BR></BR>";
                curl_close($ch);
                fclose($fh);

The cookie file gets created and chmod'ed properly. But nothing ever gets
written to it.
But remember, this code works with "four out of five websites surveyed".

Any ideas anyone? This one has had me stumped for days.

Thanks!

-= Dave =-

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.592 / Virus Database: 375 - Release Date: 2/18/2004
 
Received on 2004-02-25