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

curl-and-php

RE: meaningless characters & cookie problem

From: Cenk Uysal <cenk_uysal_at_yahoo.com>
Date: Sat, 22 Feb 2003 00:31:36 -0800 (PST)

it seems that there must be no output from my second php code. but
there is! as i said before, the data is not valid, it includes some
meanigless characters and repetations of some data portions. $result
is not empty.

*****************

i need to get cookies and transfer it during the connection because
some parts of the site needs membership. the page i gave as an
example doesnt. but for example to view the contact details of
following page, i need to logon:

http://www.alibaba.com/trade/company/goto/10108342.html

here is my code. i inspired from the example in php.net :

******************

<?php

$LOGINURL = "http://www.alibaba.com/bin/user/signin";
$GETURL = "http://www.alibaba.com/trade/company/goto/10108342.html";

$POSTFIELDS =
"Done=xxx&cc=1&step=2&UserId=MYUSERID&Password=MYPASSWORD&SignIn=+Sign+in+";

function AUTH_SITE_COOKIE_STORE($LOGINURL,$POSTFIELDS)
{
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL,"$LOGINURL");
     curl_setopt($ch, CURLOPT_COOKIEJAR,
"/usr/home/temp/cookie.txt");
                
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, "$POSTFIELDS");
     curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;
MSIE 5.01; Windows NT 5.0)");
     curl_setopt($ch, CURLOPT_REFERER, "$LOGINURL");

     ob_start();
     $result = curl_exec ($ch);
     ob_end_clean();

     curl_close ($ch);
     return "cookie.txt";
}

function AUTH_SITE_GET($GETURL,$cookieFile)
{
     $parseURL = parse_url($GETURL);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_COOKIEFILE,
"/usr/home/tmp/$cookieFile");

     curl_setopt($ch, CURLOPT_URL,"$GETURL");
     curl_setopt($ch, CURLOPT_REFERER,
"http://www.alibaba.com/bin/user/signin");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

     $result = curl_exec ($ch);
     curl_close ($ch);

     return $result;
}

$cookieFile = AUTH_SITE_COOKIE_STORE($LOGINURL,$POSTFIELDS);
echo $result = AUTH_SITE_GET($GETURL,$cookieFile);

******************

what i got from this code is the page that u can see when u connect
to the url directly. in other words, i can not login. when i look at
cookie.txt i can see there aren't correct cookie values. for example
there must be a cookie with name __cookie_client_data__ but there
isnt.

also i wonder how did u get the cookie file u show in your message? i
could never get such a result. my cookie file looks like this:

 # Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

www.alibaba.com FALSE /bin/user FALSE 0 cookie_check cookie_ok
.alibaba.com TRUE / FALSE 1145900883 __ALI_DW_ID__
LeWdiwYNOBo1QGGgYRh0tSWX63H2vIcbmPrxcA9WZMlQLkOO5MlyG986bYAZuMeY

 

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/

-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
Received on 2003-02-22