curl-and-php
Re: curl, php, and cookies
Date: Thu, 22 Dec 2011 14:09:47 -0800
A little follow up;
I added this to my script:
curl_setopt($crl, CURLOPT_HEADER, true);
the above gave me this output:
HTTP/1.1 200 OK Date: Thu, 22 Dec 2011 21:52:59 GMT Server: Apache X-Powered-By: PHP/5.2.11 Set-Cookie: bb_lastvisit=1324588217; expires=Fri, 21-Dec-2012 21:52:59 GMT; path=/; domain=.developyour.net Set-Cookie: bb_lastactivity=0; expires=Fri, 21-Dec-2012 21:52:59 GMT; path=/; domain=.developyour.net Cache-Control: private Pragma: private Transfer-Encoding: chunked Content-Type: text/html; charset=ISO-8859-1
This tells me that curl is most likely acting the way that it should, only setting the cookies which are being sent to it. This makes some sense to me, as these are the ones that are "changing". The other cookies stay constant, thus are not being sent back.
How can I then get those other cookies into the cookie.txt and not have them get deleted from the file when curl writes to it again?
Thanx.
murias
On Dec 22, 2011, at 1:27 PM, Murias O'Ceallagh wrote:
> Hello,
>
> I'm currently working on a Drupal site that is to have vBulletin content piped / streamed through it. This is all to be done with cURL, and have had moderate success so for with this. I'm having some serious issues though with the cookies the vBulletin cookies.
>
> I am relying upon a Drupal module to handle login to vBulletin, it provides a one login solution. It builds and then sets the vBulletin cookie. I then am using curl to bring the vBulletin content through the Drupal front end.
>
> To be clear though, I am writing my test / proof of concept scripts outside the realm of Drupal initially, to ensure any issues I might incur would be my code and not the Drupal API. ;^)
>
> When I run my script after successful login, the resulting page is one for a guest visitor, not logged in.
>
> I looked at the cookies.txt file that gets written to the server by curl... here is it's contents:
> # Netscape HTTP Cookie File
> # http://curl.haxx.se/rfc/cookie_spec.html
> # This file was generated by libcurl! Edit at your own risk.
>
> .developyour.net TRUE / FALSE 1356124217 bb_lastvisit 1324588217
> .developyour.net TRUE / FALSE 1356124276 bb_lastactivity 0
>
> Well, these are not all of the cookies that get set for vBulletin to use to verify user credentials.
> print_r output of $_COOKIE results in:
> [__utmz] => 3248677.1323197046.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
> [__utma] => 3248677.60611263.1323197046.1323903616.1324539537.10
> [bb_languageid] => 1
> [bb_password] => 799761acf1bfd90d7f73c2affc67eebc
> [bb_userid] => 5
> [bb_lastactivity] => 1324539572
> [bb_lastvisit] => 1324539572
> [bb_sessionhash] => 06b2a574a6a2e6987d8fb46f28bd3037
> [SESSfc831485ad71818189e3007e48b9ef98] => 8q9k5jngi223aplrqoomjkr865
> [PHPSESSID] => olvmm0o0o9mgi04qtr4hdi1211
> [has_js] => 1
>
>
> All the "bb_" are set by the login module I am using. They have the proper domain prefix of "." . They are needed by vBulletin for vBulletin to know I am actually logged into the system, and treat me as such.
>
> Here is my code:
>
> <?php
>
> echo "<pre>";
> print_r($_COOKIE);
> echo "</pre>";
>
> if(isset($_SERVER['HTTP_USER_AGENT']))
> {
> $agent = $_SERVER['HTTP_USER_AGENT'];
> echo "<br>".$agent."<br>";
> }
>
> $crl = curl_init();
> $url = "http://developyour.net/ThoughtMatrix/forums4/";
> curl_setopt($crl, CURLOPT_URL, $url);
> curl_setopt($crl, CURLOPT_COOKIESESSION, true);
> curl_setopt($crl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt");
> curl_setopt($crl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt");
> curl_setopt($crl, CURLOPT_USERAGENT, $agent);
> curl_setopt ($crl, CURLOPT_TIMEOUT, '10');
> curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
> curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt ($crl, CURLOPT_REFERER, "http://developyour.net/ThoughtMatrix/forums4/index.php");
> curl_setopt($crl, CURLOPT_POST, 1);
> $result=curl_exec($crl);
>
> print $result;
>
> curl_close($crl);
>
> ?>
>
> How can I get those other cookies into the cookie txt file? Have I missed something in my learning and understanding of curl?
>
> Thank you much in the time to read this.
> Cheers
> Murias O'Ceallagh
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2011-12-22