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

curl-and-php

RE: curl, php, and cookies

From: -Sys Adm- <centralsource_at_hotmail.com>
Date: Thu, 22 Dec 2011 17:01:17 -0500

From: lists_at_dragonsblood.net
Subject: curl, php, and cookies
Date: Thu, 22 Dec 2011 13:27:24 -0800
To: curl-and-php_at_cool.haxx.se

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.CheersMurias O'Ceallagh
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

____________

Not sure if this will help, but what I did to "read" the file contents on my cURL project was add the:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

prior to the "write" function in the cURL function.

Michael
                                               

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2011-12-22