Jump to content

CURLOPT_RETURNTRANSFER Appending


Trownt

Recommended Posts

I had a script working on my site that would connect to an SSL page, then grab contents of another page by switching the CURLOPT_URL and doing another exec. However I think my server was updated to a newer version of PHP, and it broke the script.

 

The issue is, if I do multiple curl_exec() and have CURLOPT_RETURNTRANSFER = TRUE, then it keeps appending the old response on to the new one.

 


    $curl = curl_init();

    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_TIMEOUT, 120);            
    curl_setopt($curl, CURLOPT_TIMEOUT, 45);
    curl_setopt($curl, CURLOPT_HTTPPOST, TRUE);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

    curl_setopt($curl, CURLOPT_URL, "...../test1.txt");

    $test1 = curl_exec($curl);
    echo "(".$test1.")<br />";

    curl_setopt($curl, CURLOPT_URL, "...../test2.txt");
    $test2 = curl_exec($curl);
    echo "(".$test2.")<br />";
  
    curl_close($curl);

 

GIVEN:

test1.txt is a file that just has "test1,"

test2.txt is a file that just has "test2,"

 

this script outputs:

(test1,)

(test1,test2,)

 

Is this normal? Is there anyway to clear the response? If I change CURLOPT_RETURNTRANSFER = FALSE, the the script outputs:

test1,(1)

test2,(1)

 

which is what I would expect.

Link to comment
https://forums.phpfreaks.com/topic/97179-curlopt_returntransfer-appending/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.