Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

PHP CURL problem

Hi all , I'm trying to user PHP curl to open a connection with another  server to send it a file  and  then  get the  reply to manipulate it ...

This worked fine with me :

        $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL,$target_url);
      curl_setopt($ch, CURLOPT_POST,1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
      $result=curl_exec ($ch);
      curl_close ($ch);
      //echo $result;

But , this line :
      $result=curl_exec ($ch);
do execute the CURL connection and automatically  prints the reply even when I'm commenting   the final line " the echo statement  "
So the final  reply is always printed ...
I don't  want that ..

I want to get the result  in a variable  to manipulate it not to print ..


Any advice?
0
darroosh
Asked:
darroosh
  • 2
1 Solution
 
Ray PaseurCommented:
curl_exec() does not print anything.  There is something else going on.  Can you please post the entire script exactly as you have it now?  You can obscure passwords and things like that but please make sure that the logic and line numbers are 100% the same.  Thanks, ~Ray
0
 
darrooshAuthor Commented:
Solved !

Thank you for  your  trial to help


I solved it  by adding the following  line :
      curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1);

This  line  make CURl return the output rather than directly outputting it as PHP.net says  http://au1.php.net/curl_setopt ..
It worked  fine for me ..

Thanks  again
0
 
darrooshAuthor Commented:
I searched and  found the solution .. Posted it here as it may help  someone..
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now