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 13:12:18 +1000

The problems with the second bit of code are:
1. the ob_start function collects all output from whatever comes after it
until it gets an ob_end call.
     this output is retrieved using the ob_get_contents function.
2. you store the output of curl_exec into the variable $de
3. as there is no output from the curl_exec command (since its being stored
in the $de var) there is no output for ob_start to collect
4. when you echo $result there is nothing there since its in $de

the first lot of code works because you echo the right variable.
There should be no characters at all in $result in the second lot of code
as there is a null. Unless your machine isn't initialising variable
correctly in which case there could be any amount of crap stored in the var.
In addition to which you'll find that if you take out all the ob_*
functions you'll find that the first lot of code works exactly the same as
it does in its current state (tho you'll use less processing power). have a
read up of the php manual as to how the output control functions work

><?php
>$ch =
>curl_init("http://www.alibaba.com/trade/company/cat/280501.html");
>
>curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
>
>ob_start();
>$result = curl_exec ($ch);
>ob_end_clean();
>
>curl_close ($ch);
>
>echo "$result";
>?>
>
>but it gives these meaningless characters with this code:
>
><?PHP
>$ch =
>curl_init("http://www.alibaba.com/trade/company/cat/280501.html");
>
>curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
>
>ob_start();
>$de = curl_exec($ch);
>$result = ob_get_contents();
>ob_end_clean();
>
>curl_close ($ch);
>
>echo "$result";
>?>
>
>i dont know what is wrong with second code but i dont mind anymore :)
see above

>cookie problem still goes on.
As for the cookies - by modifying your code example to include

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

which causes php to create and store any cookies recieved into the
specified file you should get something 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.

.alibaba.com TRUE / FALSE 1145877452
__cookie_client_data__
FvJk5/nm3+rfM+qFHDkaT6JGx52pt6+TH5JhguFOJXC1il0UNtF/2w==
.alibaba.com TRUE / FALSE 0 __cookie_temp_client_data__
     li0LyD93NgsfaTo+xG+nx7aTfYDB7utKc4vx9Lrvn9qWeLZn5FpsCFfV+2cS++I2zQ3f7A0yJ0OZJt
qOylmxydJrU3Dx03xP
.alibaba.com TRUE / FALSE 1145877452 __ALI_DW_ID__
HpmxsOAPNogZ4c2f2kQvpG8i99rL0oxb5va+BxNI+360TlkXPozENWGzNSldpliJrNfS7ZKGuSs=

As the code you supplied had nothing to do with cookies I can't say what
was going wrong or even where you were getting cookies from. (you dont'
actually need them in the example you provided as they are only session
cookies.)

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