Tuesday, August 2, 2011

Re: [phpXperts] Tturn this post form into PHP code

 

For this form - 

<input type="hidden" name="operation" value="create"/>
<input type="hidden" name="destination" value="checkout"/>
<p><input type="hidden" name="product_1_path"
value="/productPathGoesHere">
<input type="text" name="product_1_quantity" value="0"/> 1234-ABCD</p>
<p><input type="submit" value="Order Now"/></p>
</form>

U can try this code using curl -

<?php
  
  
  $post_fields = array
  (
    'operation' => 'create',
    'destination' => 'checkout',
    'product_1_path' => '/productPathGoesHere',
    'product_1_quantity' => '0'
  );
  
  if(!function_exists('curl_init'))
  {
    exit('mod_curl is not enabled!');
  }
  else
  {
    $ch = curl_init($post_url);
    
    if(is_resource($ch))
    {
      $curl_options = array
      (
        CURLOPT_RETURNTRANSFER => true, // Without this curl will not return output
        CURLOPT_FOLLOWLOCATION => true, // Should follow redirection?
        CURLOPT_POST => true, // we are doing a POST, not default GET
        CURLOPT_POSTFIELDS => http_build_query($post_fields), // u can directly pass the fields array as it is,
        CURLOPT_SSL_VERIFYPEER => false // U can exclude this is not posting to https://
      );
      
      $res = curl_exec($ch);
      
      if(curl_errno($ch) == 0)
      {
        // Sucess! You have also the result, do further processing with it
      }
      else
      {
        // There is an error executing the post, lets see what it is
        echo curl_error($ch);
      }
    }
    else
    {
      exit('cURL init failed!');
    }
  }
  
?>

On Tue, Aug 2, 2011 at 12:46 PM, raj_corporatemunim <raj_corporatemunim@yahoo.com> wrote:
 

-- changed the website url to which to post --

<form method="POST" action="http://sites.fastspring.com/YourCompanyOrAccountName/api/order">
<input type="hidden" name="operation" value="create"/>
<input type="hidden" name="destination" value="checkout"/>
<p><input type="hidden" name="product_1_path"
value="/productPathGoesHere">
<input type="text" name="product_1_quantity" value="0"/> 1234-ABCD</p>
<p><input type="submit" value="Order Now"/></p>
</form>

I have tried

if (!function_exists('fopen'))
{echo' not allowd fopen ';}

$params = array('http' => array(
'method' => 'post',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}

but does not work and throws exception, am I doing something wrong or there is alternate way to do it or can it be issue with hosting, I am using 1and1.

Any help is appreciated.




--
Anjan Bhowmik
Freelance Software & Web Developer
M : +880 - 1670 - 556419
E : anjan011@gmail.cominfo@ultrasoftbd.com
Site: http://www.onlyfreelancer.com/ - Only for Freelancer's!

__._,_.___
Recent Activity:
Visit phpXperts website at www.phpxperts.net
.

__,_._,___

No comments: