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

curl-and-php

RE: meaningless characters & cookie problem

From: Dave Withnall <withnall_at_connexus.net.au>
Date: Sat, 22 Feb 2003 22:43:21 +1000

At 12:31 AM 22/02/2003 -0800, Cenk Uysal wrote:

>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'll trust you on the $result not being empty, but I couldn't replicate it.
I found your duplicate data, I'd recommend looking into what the
meaningless characters actually are before saying they're completely
meaningless. Wotever the output is coming from the server is what you're
getting, I seriously doubt curl has anything to do with duplicating 3 lines
at the end of a page where it doesn't actually do it with the 2 preceding
pages you need to get for your cookies (see below for more details)

>*****************
>
>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

This page doesn't actually require a login to view. but anyways back to
your cookie issue

The code you sent doesn't work because you are not doing what a normal
browser would do.
This example gets you the full cookies you're after

function AUTH_SITE_COOKIE_STORE($LOGINURL, $POSTFIELDS) {
   $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $LOGINURL);
     curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); // Connect to the
login page and get the session ID cookie & some other temp cookie
     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;MSIE
5.01; Windows NT 5.0)");
     ob_start();
         curl_exec ($ch);
     ob_end_clean();
   curl_close($ch);

   $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $LOGINURL);
     curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); // Get the login
cookies and other stuff
     curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); // send back the
session ID & wotever the temp cookie was.
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, -1); // Go where the site
tells me to go
     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)");
     ob_start();
       curl_exec ($ch);
     ob_end_clean();
   curl_close ($ch);

   return "cookie.txt";
}

Always remember - If at first it falls over -> do exactly what a browser
would do, don't skip steps. You'll prolly find that its important.
Also, you don't need to put quotes around string variables, that was
confusing to start with.

I also noticed that you modified the POST string being sent.
By default the site puts this in
Done=/bin/home/ehomepage (don't forget to urlencode the /'s)

where you've got
Done=xxx

but you might have done that deliberately to block out something sensitive...

The cookie file from this is rather large:

# 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 null
.alibaba.com TRUE / FALSE 1145915463 __ALI_DW_ID__
jvORKMjIXXItR+EpvdV+HH9QVCirGb1O2SxFz2jZfWDkSKgUZsyAUAkECxKDc8Ft7US
JSvwsJI8=
.alibaba.com TRUE / FALSE 1145919780
__cookie_client_data__
bKDLbT2pUycpBLVzvtdiYfjjTkDLW3K2Mwg4SXj0zqhnF4lpfvwl4QY6wkB
w10GK6nxg2rvMZ/U=
.alibaba.com TRUE / FALSE 0 __cookie_temp_client_data__
     VJhIHk6gxRx5xe5ZHGeJ/u1NRGBu+/uItwGLdj4gIr2cdig5Rx4N9iOa1hN
zyAjymCnEFpjFcWy0aBH5KGD029v3L3iCtO7FllpySNjgUUJd67+oGPTn4eoFMB0hAoHhPgaap0GkhLow18fSPzGFjUT8+Z22X7ir44Qau4k9tPaQCn/uFVGOA6TPhMpd5X+UNIloNa
ik5ZVQWeMlgEj+fQNn3v0whPBPoRhbdb+aBHjRsweddRkSati14tRpcwb/D/ZiJlWeZqlHQCu3FRYkgi4WMDaa/B5KsAkXs2XOOoCf5Hx/K4yjr88tbo/7QFSSMUGgByE6FkdnhkLYR
9EbR+RP6njMyo7Zg4/r+q0POdaJJbqz8jVr4EtrIAqUHzBRymrkytfXLub2i9FmNJcBJaaF5DYi5D7lKke20MO1TgLrAgOi2NSS4IwZGI2LdrxmVFAaOSEl6sQqS5w1hSSndA==

-------------------------------------------------------
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