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

curl-and-php

Re: CURL, POST an Cookies???- AGAIN!!!

From: Alexei Zoubov <tech_at_alexeiz.com>
Date: Mon, 24 Nov 2003 08:40:18 -0800

Here is almost the whole problem.

Script 1- subscribes the person to a mailing list. This script works
well - no surprises!

$url ='www.superpayline.com/SAFELIST/signup.php' ;
  $post_arr = array (username => 'alexei', password => 'govno',contact
=> 'emcont_at_domain.com',
    list => 'emcont_at_domain.com', action= => 'click here to join');

  if (!$c = curl_init()) return "Bad connection!";
    curl_setopt($c, CURLOPT_POST, true);
    curl_setopt($c, CURLOPT_POSTFIELDS, $post_arr);
    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($curld, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($c);
    echo $output;
curl_close($curld);

Script 2 - loging and posting a message to this mailing list. First we
have to
log in with username and password. We know that the mailing list script
sets
the cookies for username and password, not necessarily with the same
names, so
first we send loging script, then ectract cookie information from the
header
returned and send request again.

There seem to be two possibilities to deal with cookies - just parse the
header or write the receiver cookies to afile with COOLIEJAR and then
submit
them by using COOKIE FILE.

I'll start with simple parsing (I don't give the parser script, it
works well, just the results).

$url_l = 'http://www.superpayline.com/SAFELIST/members/login.php';
$post_arr_l = array (username => 'alexei', password => 'govno', action=
=> 'click here to login');

   if (!$c2 = curl_init()) return "Bad connection!";
   curl_setopt($c2, CURLOPT_POST, true);
   curl_setopt ($c2, CURLOPT_HEADER,1);
   curl_setopt($c2, CURLOPT_POSTFIELDS,$post_arr_l);
   curl_setopt($c2, CURLOPT_URL, $url_l);
   curl_setopt($c2, CURLOPT_RETURNTRANSFER, true);
   $output2 = curl_exec($c2);
   curl_close($c2);

         ** <<The whole page is returned in $output2, then parsed. Here is the
header returned
        HTTP/1.1 100 Continue
        
        HTTP/1.1 200 OK
        Date: Mon, 24 Nov 2003 16:20:37 GMT
        Server: Apache/1.3.27 (iTools/MacOSX) mod_ssl/2.8.12 OpenSSL/0.9.6g
PHP/4.3.2 mod_perl/1.26 mod_fastcgi/2.2.12
        X-Powered-By: PHP/4.3.2
        Set-Cookie: splistmem=alexz; expires=Mon, 24-Nov-03 17:20:37 GMT
        Set-Cookie: splistpass=govno; expires=Mon, 24-Nov-03 17:20:37 GMT
        Transfer-Encoding: chunked
        Content-Type: text/html
        
        **It is pretty easy to extract cookie info and then send it back in
the next request:
        
$url_l = 'http://www.superpayline.com/SAFELIST/members/login.php';
$post_arr_l = array (username => 'alexei', password => 'govno', action=
=> 'click here to login');

    if (!$c3 = curl_init()) return "Bad connection!";
    curl_setopt($c3, CURLOPT_POST, true);
    curl_setopt ($c3, CURLOPT_HEADER,1);
    curl_setopt($c3, CURLOPT_POSTFIELDS,$post_arr_l);
    curl_setopt($c3, CURLOPT_URL, $url_l);
    curl_setopt($c3,CURLOPT_COOKIE,'splistmem=alexz; expires=Mon,
24-Nov-03 17:20:37 GMT');
    curl_setopt($c3,CURLOPT_COOKIE,'splistpass=govno; expires=Mon,
24-Nov-03 17:20:37 GMT');
    curl_setopt($c3, CURLOPT_RETURNTRANSFER, 1);
    $output3 = curl_exec($c3);
   curl_close($c3);

echo "<p> $output3";

**** The idea is that after this second request cookies splistmem and
splistpass are set and we can submit the next request to another page
actually
posting the email message there. Nevertheless the cookies are NOT set
at the
client were we need them. Something is very wrong!

I also tried to write received cookies to "cookies.txt" file by using:

     curl_setopt($c2, CURLOPT_COOKIEJAR, "cookies.txt");

and then sending them in the next request with

     curl_setopt($c3, CURLOPT_COOKIEFILE, "cookies.txt");

Well, cookies get written to the file, but after that - nothing!

So here is most of the story - I listed only a small part of all
options I
tried. It is already a week of fighting with it and I'm still nowhere!

Very sad Alexei.

On Sunday, November 23, 2003, at 10:53 PM, Daniel Stenberg wrote:

> On Sun, 23 Nov 2003, Alexei Zoubov wrote:
>
>> I REALLY need help - does anybody has any idea?
>>
>> $post_arr = array (username =>'alexeiz' ,password =>'GOVNO');
>> $c = curl_init('http://www.sampledomain.com/login.php');
>> curl_setopt($c,CURLOPT_VERBOSE,1);
>> curl_setopt($c, CURLOPT_POSTFIELDS, $post_arr);
>> curl_setopt($c,CURLOPT_COOKIE,'username=alexeiz; password='GOVNO');
>> curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
>> $page = curl_exec($c);
>> curl_close($c);
>>
>> This script does login correctly. But it also supposed to set cookies
>> on the client that triggers this script and it does NOT!
>
> This script does not "set cookies on the client". It passes cookies to
> the
> server. Nothing else.
>
>> These cookies are needed so in the next CURL call the client can
>> access
>> other pages at www.sampledomain.com that require these cookies to
>> authorize
>> the client.
>
> Then you need to post those cookies in the next request, not in this
> one.
>
>> Is there anything wrong here, and if it is, how to achieve this goal?
>
> Something is wrong since you can't make it work. I don't think it is a
> bug in
> curl though.
>
> --
> Daniel Stenberg -- http://curl.haxx.se/ -- http://daniel.haxx.se/
> [[ Do not post private mails to this email address. They won't reach
> me. ]]
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
>

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
Received on 2003-11-24