Using curl to submit/retrieve a forms results
        Posted  
        
            by 
                Jason
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jason
        
        
        
        Published on 2011-01-03T22:52:01Z
        Indexed on 
            2011/01/03
            22:53 UTC
        
        
        Read the original article
        Hit count: 217
        
I need help in trying to use curl to post data to a page and retrieve the results after the form has been submitted.
I created a simple form:
<form name="test" method="post" action="form.php">
<input type="text" name="name" size="40" />e <input type="text" name="comment" size="140" /> <input type="submit" name="submit" value="submit" /> </form>
In addition, I have php code to handle this form in the same page. All it does is echo back the form values.
The curl that I have been using is this:
  $h = curl_init();
  curl_setopt($h, CURLOPT_URL, "path/to/form.php"); 
  curl_setopt($h, CURLOPT_POST, true);
  curl_setopt($h, CURLOPT_POSTFIELDS, array(
'name' => 'yes', 'comment' => 'no' )); curl_setopt($h, CURLOPT_HEADER, false); curl_setopt($h, CURLOPT_RETURNTRANSFER, 1);
  $result = curl_exec($h);
When I launch the page with the curl code in it, I get the form.php page contents but it doesn't not show the variables that PHP should have echo'd when the form is submitted.
would appreciate any help with this.
Thanks.
© Stack Overflow or respective owner