curl-and-php
Re: post operation does not return any results
Date: Wed, 5 Jun 2002 17:21:59 +0200 (MET DST)
On Mon, 27 May 2002, Pras wrote:
[ I'm mainly replying here since no one else did ]
> I have 2 scripts. One sends a variable via a post operation through curl to
> another script. The second script contains an if structure to evaluate the
> content of the variable, and it should return a string based on that. here
> are the 2 scripts:
>
> ***********************************************
> page2.php - the one that uses curl
> ------------------------------------
> <?php
> $ch = curl_init ("page3.php");
>
> curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt ($ch, CURLOPT_HEADER, 0);
> curl_setopt($ch, CURLOPT_POST,1);
> curl_setopt ($ch, CURLOPT_POSTFIELDS, "test=inprogress");
> $result = curl_exec ($ch);
> curl_close ($ch);
>
> echo $result;
> ?>
page3.php - the script that processes the data
----------------------------------------------
<?php
if ($_POST['test'] == 'inprogress')
{
return 'test is in progress';
}
else
{
return 'not working';
}
?>
> In page2.php, nothing is output when the echo $result; line is encountered.
> I also tried echoing instead of returning a string in page3.php.
> Additionally, I tried writing output to a file in page3.php but none of
> these methods worked. Nothing is written to the file.
The page2 will get the response back from page3. I don't know PHP, but I
don't think 'return' is the proper way to output stuff/a response as HTML (or
whatever you wanna output).
The page2 curl_init() call does not use a proper URL. Doesn't this cause an
error or something?
> Apparently, the page3.php script isn't even being executed.
Very likely.
> Is this what is supposed to happen?
Yes, you must point to it with a proper URL and then it'll have better
chances of working.
> How can I obtain a result of the post operation?
RETURNTRANSFER is the way, AFAIK.
I am not a PHP hacker.
-- Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/ _______________________________________________________________ Don't miss the 2002 Sprint PCS Application Developer's Conference August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfmReceived on 2002-06-05