Richard Lynch | 1 May 2012 04:42

Re: COOKIEFILE COOKIEJAR empty

Nothing so complex...

I'm embarrassed to report that I somehow managed to delete the
COOKIEJAR line...

Not one of my better days.

On Mon, April 30, 2012 11:15 am, Shanshui Liu wrote:
> Maybe the cookies are not set by HTTP headers at all (e.g. via
> JavaScript).
> Have you looked through the headers to see whether "Set-Cookie:" does
> exist? Also, modified versions of PHP (e.g. Suhosin) might prevent
> scripts
> from writing to files not owned by the same user as the web server /
> PHP
> CGI process, so you may want to try running a chown (change owner) on
> the
> cookie file? (I'm not familiar with server adminstration stuff
> though.)
>
> With regards,
> Liu Shan Shui
> http://lx.sg/
> "Life would be much easier if I had the source code." - Anonymous
>
>
> On Mon, Apr 30, 2012 at 10:12 PM, Richard Lynch <ceo <at> l-i-e.com> wrote:
>
>> I'm having trouble with CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR in
>> PHP.
(Continue reading)

Shanshui Liu | 1 May 2012 06:46
Picon
Favicon
Gravatar

Re: COOKIEFILE COOKIEJAR empty

Heh. Anyway, glad to see that it's now resolved.


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


On Tue, May 1, 2012 at 10:42 AM, Richard Lynch <ceo <at> l-i-e.com> wrote:
Nothing so complex...

I'm embarrassed to report that I somehow managed to delete the
COOKIEJAR line...

Not one of my better days.

On Mon, April 30, 2012 11:15 am, Shanshui Liu wrote:
> Maybe the cookies are not set by HTTP headers at all (e.g. via
> JavaScript).
> Have you looked through the headers to see whether "Set-Cookie:" does
> exist? Also, modified versions of PHP (e.g. Suhosin) might prevent
> scripts
> from writing to files not owned by the same user as the web server /
> PHP
> CGI process, so you may want to try running a chown (change owner) on
> the
> cookie file? (I'm not familiar with server adminstration stuff
> though.)
>
> With regards,
> Liu Shan Shui
> http://lx.sg/
> "Life would be much easier if I had the source code." - Anonymous
>
>
> On Mon, Apr 30, 2012 at 10:12 PM, Richard Lynch <ceo <at> l-i-e.com> wrote:
>
>> I'm having trouble with CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR in
>> PHP.
>>
>> I have tried ./cookies.txt and /full/path/to/cookies.txt
>>
>> I have them at 777 in sheer desperation.
>>
>> Are there any checks in libcurl for keeping me from shooting myself
>> in
>> the foot with owner/group/permission?
>>
>> I am using RETURNTRANSFER and FOLLOWLOCATION.
>>
>> I seem to remember having issues with CURLOPT_HEADER in conjunction
>> with COOKIE* way back when. It felt like since I was getting the
>> headers, libcurl didn't feel the need to track cookies for me...
>>
>> Are there any known incompatibilities among those three?
>>
>> I need to make a second request in another HTTP transaction, so I'm
>> pretty sure I need those cookies, and I'd rather not parse the
>> headers
>> for them...  Especially as there might be one set by an interstitial
>> page, so I'd have to also follow the 30* redirects by hand as well.
>>
>> --
>> brain cancer update:
>> http://richardlynch.blogspot.com/search/label/brain%20tumor
>> Donate:
>>
>> https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE
>>
>>
>> _______________________________________________
>> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Earl Brown | 7 May 2012 08:24

FOLLOWLOCATION as true doesn't seem to work

PHP curl users,

I can't figure out why I can't get the html source code of:

http://corpusdelespanol.org/x2.asp

even though I can get the source code of:

http://corpusdelespanol.org/x.asp
http://corpusdelespanol.org/x1.asp
http://corpusdelespanol.org/x3.asp
http://corpusdelespanol.org/x4.asp

My PHP script starts at x.asp and gets a cookie and then passes
sequentially through the webpages. For some reason I can't get the
source code of x2.asp. Instead, I get the source of blank.asp. When I
use a browser (whether, Firefox, Chrome, Opera) I can see the source
code of x2.asp accurately, but curl doesn't give it to me. Instead it
gives me the source code of blank.asp, even though I have
FOLLOWLOCATION as true. I'm at a loss. One idea: x2.asp as some style
tag definitions above the opening <html> tag while the other pages
don't; the others start with the opening <html> tag and then define
styles. Could that throw off curl? Are browsers able to correct this
while curl is not? Here's my PHP script:

start of script
_____________

<?php

if (empty($_GET['word'])) {
die("Need to specify the word as a GET parameter, i.e. ?word=&lt;word&gt;");
}

$ch = curl_init();

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch,CURLOPT_HEADER,true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Macintosh; Intel Mac
OS X 10_7_2) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202
Safari/535.12011-10-16 20:21:13');

curl_setopt($ch,CURLOPT_URL,'http://corpusdelespanol.org/x.asp');

curl_exec($ch);

curl_setopt($ch,CURLOPT_URL,'http://corpusdelespanol.org/x1.asp');

curl_exec($ch);

curl_setopt($ch,CURLOPT_URL,'http://corpusdelespanol.org/x2.asp?chooser=seq&p='
. urlencode($_GET['word']) .
'&w2=&wl=4&wr=4&r1=&r2=&ipos1=-select-&B7=SEARCH&sec1=19&sec1=18&sec2=0&sortBy=freq&sortByDo2=alph&minfreq1=freq&freq1=4&freq2=4&numhits=100&kh=100&groupBy=words&whatshow=raw&saveList=no&corpus=cde&ownsearch=y&holder=&whatdo=seq&rand1=y&whatdo1=1&didRandom=n&minFreq=freq&s1=1&s2=2&s3=3&perc=mi');

$second_page = curl_exec($ch);

echo $second_page . "<br /><br /><br />";

curl_setopt($ch,CURLOPT_URL,'http://corpusdelespanol.org/x3.asp?r=23&w11='
. urlencode($_GET['word']));

$inpage = curl_exec($ch);

preg_match('|<span ID="w_section">SECTION</span>:
ORAL&nbsp<b>\(([0-9,]*)\)</b></td>|Ui', $inpage, $matches);

echo str_replace(',', '', $matches[1]);

__________
end of script

Instead of giving me what I see as the source of x2.asp in a browser,
I get this header and then the source of blank.asp:

HTTP/1.1 302 Object moved
Date: Mon, 07 May 2012 05:49:52 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Location: blank.asp
Content-Length: 130
Content-Type: text/html
Cache-control: private

HTTP/1.1 200 OK
Date: Mon, 07 May 2012 05:49:52 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 755
Content-Type: text/html
Cache-control: private

I have assumed FOLLOWLOCATION as true would fix this problem, but it
doesn't. Any ideas?

Thank you for your help. Best, Earl Brown

--
Earl K. Brown, PhD
Chair, Language ULR Committee
Assistant Professor of Spanish Linguistics
School of World Languages and Cultures
California State University, Monterey Bay

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

Richard Lynch | 7 May 2012 18:56

libcurl multi same domain patch for thread safety somewhere near 7.20.x release

I think I am facing this issue on a GoDaddy site
(I know, the client picked):
http://curl.haxx.se/mail/lib-2009-04/0028.html

This makes me think it was fixed in 7.20.x
https://bugs.php.net/bug.php?id=47773

I see entries about thread safety in both 7.20.0 and 7.20.1:
7.20.0
multi interface with OpenSSL read already freed memory when closing down

7.20.1
threaded resolver double free when closing curl handle

Does anybody know which of those matches my issue here:
https://bugs.php.net/bug.php?id=61947
(There is a backtrace fo the libcurl part.  Mostly luck, honestly)

I certainly appreciate any help here, especially because I'm pretty
sure it's going to come from an incredibly busy expert at libcurl...

Knowing GoDaddy, if they'll upgrade at all, they'll decide 7.20.0 is
"far enough" and, with my luck, I need 7.20.1 or something...

--

-- 
brain cancer update:
http://richardlynch.blogspot.com/search/label/brain%20tumor
Donate:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

Daniel Stenberg | 8 May 2012 08:56
Picon
Favicon
Gravatar

Re: libcurl multi same domain patch for thread safety somewhere near 7.20.x release

On Mon, 7 May 2012, Richard Lynch wrote:

> I see entries about thread safety in both 7.20.0 and 7.20.1:

...

> Does anybody know which of those matches my issue here:
> https://bugs.php.net/bug.php?id=61947

It really isn't easy to tell as I don't recall the specifics of those problems 
anymore. If you really need to know I can only suggest that you install local 
libcurl versions and run tests against them.

--

-- 

  / daniel.haxx.se
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

Picon

How to post base64 variable like file ?




 //I get pictures from database in base64 format:

$ready_img = 'data:image/jpg;base64,' . $val["image"];

//Then I try to post it to server:

//multipart
$postdata = array(
"data[title]=' . $obj['sp_header'] . ",
"data[category_id]=' . '1147' . ",
"image[1]=' . $ready_img . ";type=image/jpeg;filename=test.jpg ");


$cmd_line = ("h:/curl/bin/curl.exe " . implode(" ", $proxy_data) . " " . implode(" ", $start_data) . " " . implode(" ", $headers_data) . " -F " . implode(" -F ", $postdata) . " " . implode(" ", $cookie_data) . " " .$url_data);

//execute curl
$out = shell_exec($cmd_line);

//But this variant don't work ...
//Please help me

// P.S. save image to file and then post it to server in this case can not be

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Picon

redirect don't work


 Hi!  I am from Ukraine :) 

So I have this code and a question: 

// CODE ---------------------------------------------------------------
 $login_value = $_GET["login_value"];
$password_value = $_GET["password_value"];


$postdata = array(
   'login[email]' => $login_value,
   'login[password]' => $password_value
   );

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://slando.ua/account/?ref%5B0%5D%5Baction%5D=user&ref%5B0%5D%5Bmethod%5D=index");

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1");

$headers = array
(
'Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1',
'Accept-Language: ru-RU,ru;q=0.9,en;q=0.8',
'Accept-Encoding: deflate',
'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7',
'Expect:'
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_ENCODING, "");

curl_setopt($ch, CURLOPT_REFERER, "http://slando.ua/account/?ref%5B0%5D%5Baction%5D=user&ref%5B0%5D%5Bmethod%5D=index");

$cookie_file_path = create_tmp_cookie($user_prm["sp_login"], "libcurl");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$out = curl_exec($ch);

echo "\n\ncURL error number:" . curl_errno($ch) . " <br/>";
echo "\n\ncURL error:" . curl_error($ch) . " <br/>";
print_r(curl_getinfo($ch));

when i do this at my local (home) webserver - all ok! 
i get this: 

//  LOCAL RESULT -----------------------------------------------
cURL error number:0 <br/>

cURL error: <br/>Array
(
[url] => http://slando.ua/my/
[content_type] => text/html
[http_code] => 200
[header_size] => 748
[request_size] => 1352
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 1
[total_time] => 0.312
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 274
[size_download] => 29996
[speed_download] => 96141
[speed_upload] => 878
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.125
[redirect_time] => 0.078
[certinfo] => Array
(
)

)
//---------------------------------------------------------
 but if i use same code at the hosting - redirect don't work! 
// HOSTING RESULT ---------------------------------------

cURL error number:0 <br/>

cURL error: <br/>Array
(
[url] => http://slando.ua/account/?ref%5B0%5D%5Baction%5D=user&ref%5B0%5D%5Bmethod%5D=index
[content_type] => text/html
[http_code] => 301
[header_size] => 326
[request_size] => 685
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.226617
[namelookup_time] => 1.5E-5
[connect_time] => 0.03563
[pretransfer_time] => 0.035677
[size_upload] => 274
[size_download] => 0
[speed_download] => 0
[speed_upload] => 1209
[download_content_length] => 0
[upload_content_length] => 274
[starttransfer_time] => 0.035679
[redirect_time] => 0
)

what is the problem ? 
Thank you for help! 


_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Picon

redirect don't work ?




С уважением, Роман Ковальский Hi! I am from Ukraine :)

So I have this code and a question:

// CODE ---------------------------------------------------------------
$login_value = $_GET["login_value"];
$password_value = $_GET["password_value"];


$postdata = array(
'login[email]' => $login_value,
'login[password]' => $password_value
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://slando.ua/account/?ref%5B0%5D%5Baction%5D=user&ref%5B0%5D%5Bmethod%5D=index");

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1");

$headers = array
(
'Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, * /*;q=0.1',
'Accept-Language: ru-RU,ru;q=0.9,en;q=0.8',
'Accept-Encoding: deflate',
'Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7',
'Expect:'
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_ENCODING, "");

curl_setopt($ch, CURLOPT_REFERER, "http://slando.ua/account/?ref%5B0%5D%5Baction%5D=user&ref%5B0%5D%5Bmethod%5D=index");

$cookie_file_path = create_tmp_cookie($user_prm["sp_login"], "libcurl");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$out = curl_exec($ch);

echo "\n\ncURL error number:" . curl_errno($ch) . " <br/>";
echo "\n\ncURL error:" . curl_error($ch) . " <br/>";
print_r(curl_getinfo($ch));

when i do this at my local (home) webserver - all ok!
i get this:

// LOCAL RESULT -----------------------------------------------
cURL error number:0 <br/>

cURL error: <br/>Array
(
[url] => http://slando.ua/my/
[content_type] => text/html
[http_code] => 200
[header_size] => 748
[request_size] => 1352
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 1
[total_time] => 0.312
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 274
[size_download] => 29996
[speed_download] => 96141
[speed_upload] => 878
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.125
[redirect_time] => 0.078
[certinfo] => Array
(
)

)
//---------------------------------------------------------
but if i use same code at the hosting - redirect don't work!
// HOSTING RESULT ---------------------------------------

cURL error number:0 <br/>

cURL error: <br/>Array
(
[url] => http://slando.ua/account/?ref%5B0%5D%5Baction%5D=user&ref%5B0%5D%5Bmethod%5D=index
[content_type] => text/html
[http_code] => 301
[header_size] => 326
[request_size] => 685
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.226617
[namelookup_time] => 1.5E-5
[connect_time] => 0.03563
[pretransfer_time] => 0.035677
[size_upload] => 274
[size_download] => 0
[speed_download] => 0
[speed_upload] => 1209
[download_content_length] => 0
[upload_content_length] => 274
[starttransfer_time] => 0.035679
[redirect_time] => 0
)

what is the problem ?
Thank you for help!

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
shiplu | 25 May 2012 22:39
Picon
Gravatar

Re: redirect don't work ?



On Sat, May 26, 2012 at 2:25 AM, Роман Ковальский <steel_d <at> mail.ru> wrote:
if i use same code at the hosting - redirect don't work!

On the hosting, did you check the response instead of headers?? The error might be described there. 

--
Shiplu.Mokadd.im
ImgSign.com | A dynamic signature machine
Innovation distinguishes between follower and leader

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php

Gmane