0

I want to use cURL to post some data to an external URL, here is the code they ask to embed, for some technical needs I need to create my own form action so I need cURL so POST those data: This is what I am asked to embed:

<form action='https://external.com/blabla' name=715000002374001 method='POST'>  
<input type='text'name='xnQsjsdp' value='c942f375287f707b73'/>  
<input type='hidden' name='zc_gad' id='zc_gad' value=''/> 
 <input type='text'name='xmIwtLD' value=1aff1efd0a4'/>  
<input type='text' name='actionType' value='TGVhZHM='/> 
<input type='text' name='returnURL' value='http&#x3a;&#x2f;&#x2f;www.blabla.de' />
</form>

I try to make it with cURL :

  $data = 'xnQsjsdp=c942f375287f707b73&xmIwtLD=TGVhZHM&actionType=TGVhZHM&returnURL&http&#x3a;&#x2f;&#x2f;www.blabla.de';
  $ch = curl_init();
  curl_setopt($ch,CURLOPT_URL,'https://external.com/blabla');
  curl_setopt($ch, CURLOPT_URL,$url);
  //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data );
  $res = curl_exec ($ch);
  curl_close ($ch);

But seems not to be working !!!

2
  • try printing curl error if(curl_exec($ch) === false) { echo 'Curl error: ' . curl_error($ch); } Commented Feb 23, 2017 at 10:08
  • I am not having any error Commented Feb 23, 2017 at 10:53

1 Answer 1

1

You can use this class like

class YourClass
{

   private static $base_url = 'http://localhost/projects/';
   private static $key = 'your_key';
   private static $secret = 'your_secret';

   public static function yourMethodName($id = '', $fields = '', $is_return_transfer = 0)
   {

      if (is_array($fields))
      {
         $fields_str = http_build_query($fields, '', '&');
      } else
      {
         $fields_str = $fields;
      }
      $fields_str = $fields_str . "&key=" . self::$key . "&secret=" . self::$secret;
      $id_str = ($id != '') ? "/$id" : "";
      $url = self::$base_url . $id_str;

      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_POST, count($fields));
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_str);
      if ($is_return_transfer == 1)
      {
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      }
      $result = curl_exec($ch);
      curl_close($ch);
      return $result;
   }

}

You can use this like YourClass::yourMethodName($id, $fields, $is_return_transfer);

Sign up to request clarification or add additional context in comments.

2 Comments

I have no $key and no $secret. I wrote all I have
If you want to validate privacy you can use that key and secret or delete that line like private static $key = 'your_key'; private static $secret = 'your_secret'; and $fields_str = $fields_str . "&key=" . self::$key . "&secret=" . self::$secret;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.