cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-and-php Archives

curl, php, and cookies

From: Murias O'Ceallagh <lists_at_dragonsblood.net>
Date: Thu, 22 Dec 2011 13:27:24 -0800

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
Received on 2011-12-22

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET