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

curl-and-php

Re: curl, php, and cookies

From: Shanshui Liu <me_at_lx.sg>
Date: Fri, 23 Dec 2011 06:13:49 +0800

It's possible that the cookies are set using JavaScript (the "has_js" key
there is a big hint), and cURL don't parse them like a web browser does. In
that case, you may have to extract the cookie values from the responses
using regular expressions and append it to the cookie.

With regards,
Liu Shan Shui
http://lx.sg/
"Life would be much easier if I had the source code." - Anonymous

On Fri, Dec 23, 2011 at 5:27 AM, Murias O'Ceallagh
<lists_at_dragonsblood.net>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