title: PHP send updated POST request to external server and visit page
body: <p>I am using the Cashflows online payment system, and am trying to submit a dynamically generated price to their server, based on a form on a webpage. However, inside the POST request that I need to send to the Cashflows terminal, I need to include an input field with a hash key. My problem is that the hash is based on a secret key, and this key is generated with one of the parameters being the price (see below), as the <a href="http://www.cashflows.com/support/kb/payment_page_integration_guide.pdf" rel="nofollow">integration guide</a> suggests.</p>
  
  <p>How can I submit the form with the POST parameters below to the portal using PHP?</p>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>&lt;?php
  
      $secret_key = 'foobar';
      $store_id = $_POST['store_id'];
      $cart_id = $_POST['cart_id'];
      $amount = $_POST['amount'];
      $currency = $_POST['currency'];
      $test = $_POST['test'];
      $description = $_POST['description'];
      echo $check = hash('sha256', $secret_key . ':' . $store_id . ':' . $cart_id . ':' . $amount . ':' . $currency . ':' . $test . ':' . $description);
      $price = $_POST['price'];
      $qty = $_POST['qty'];
      $carriage_amount = $_POST['carriage_amount'];
      $postage_and_packaging = $_POST['postage_and_packaging'];
      $name = $_POST['name'];
      $address = $_POST['address'];
      $postcode = $_POST['postcode'];
      $country = $_POST['country'];
      $tel = $_POST['tel'];
      $email = $_POST['email'];
      $amount = $_POST['amount'];
  
  ?&gt;
  </code></pre>
  
  <p><strong>Form with dynamically generated price, a modified version of their <a href="http://www.cashflows.com/support/index.php?page=developers&amp;sub=hosted_payment_page&amp;subsub=hosted_payment_page_examples" rel="nofollow">integration example</a>:</strong></p>
  
  <pre><code>&lt;form action="submit.php" method="POST"&gt;
      &lt;input type="hidden" name="store_id" value="5939523" /&gt;
      &lt;input type="hidden" name="cart_id" value="captubes" /&gt;
      &lt;input type="hidden" name="currency" value="GBP" /&gt;
      &lt;input type="hidden" name="test" value="1" /&gt;
      &lt;input type="hidden" name="description" value="Fruush" /&gt;
      &lt;input type="hidden" name="check" value="SOME KEY HERE" /&gt;
  
      &lt;script type="text/javascript" type="text/javascript"&gt;
  
          // The next two functions round numbers to numerical formatting. They do not need to be altered when adding or removing products.
          function roundOff2(value, precision) {
              return places(value,1,precision);
          }
  
          function places(X, M, N) {
              var T, S=new String(Math.round(X*Number("1e"+N)))
              while (S.length&lt;M+N) S='0'+S
              var y = S.substr(0, T=(S.length-N));
              if(N&gt;0) 
              {
                  y += '.' + S.substr(T, N);
              }
  
              return y;
          }
  
          // This function checks for empty quantities. It does not need to be altered when adding or removing products.
          function CheckNull2(value) {
              if (value == "") {
                  value = "0";
              }
  
              return value;
          }
  
          // This function defines the postage and packaging location. It does not need to be altered when adding or removing products.
          function typeOfCarriage(x,whereabouts) {
              x.carriage_amount.value = whereabouts;
          }
  
          // This function addeds the postage and packaging to the total price of the products. Add new postage rates here, and also edit further down the page to add them to the table.
          function calculate(x) {
  
              basicprice = calc(x);
  
              if( Number(basicprice) &gt; 0 ) {
  
                  var postage_and_packaging = 0;
  
                  switch (x.carriage_amount.value) {
                      case "uk" :
                          postage_and_packaging = 1.99;
                          break;
                      case "europe" :
                          postage_and_packaging = 2.99;
                          break;
                      default :
                          postage_and_packaging = 4.99;
                          break;
                  }
  
                  x.amount.value = Number(basicprice) + postage_and_packaging;
  
              } else {
  
                  x.amount.value = "0";
  
              }
  
              x.amount.value = roundOff2(x.amount.value,2);
  
          }
  
          // The standard price, exluding postage and packaging is calculated here. It does not need to be altered when adding or removing products.
          function calc(x) {
  
              var b = Number(CheckNull2(x.price.value));
              var c = Number(CheckNull2(x.qty.value));
              var a = (b * c);
  
              return a;
  
          }
  
      &lt;/script&gt;
  
      &lt;p&gt;
          &lt;h3&gt;Number of caps&lt;/h3&gt;
          Tube of 6 caps: &amp;pound;4.99 - Quantity: &lt;input name="price" value="4.99" type="hidden" /&gt;&lt;input name="qty" size="3" value="1" /&gt;
      &lt;/p&gt;
  
      &lt;p&gt;
          &lt;h3&gt;Postage &amp;amp; Packaging:&lt;/h3&gt;
          &lt;input name="carriage_amount" value="uk" type="hidden"&gt;
          &lt;input checked="checked" name="postage_and_packaging" onClick="typeOfCarriage(this.form,'uk');calculate(this.form)" value="" type="radio" /&gt;UK (&amp;pound;1.99)
          &lt;input name="postage_and_packaging" onClick="typeOfCarriage(this.form,'europe');calculate(this.form)" value="" type="radio" /&gt;Europe(&amp;pound;2.99)
          &lt;input name="postage_and_packaging" onClick="typeOfCarriage(this.form,'world');calculate(this.form)" value="" type="radio" /&gt;Rest of World (&amp;pound;4.99)
      &lt;/p&gt;
  
      &lt;p&gt;
          &lt;h3&gt;Your Details (you will get a chance to change these):&lt;/h3&gt;
          &lt;span style="width: 100px; float: left;"&gt;Name:&lt;/span&gt; &lt;input type="text" name="name" /&gt;&lt;br /&gt;
          &lt;span style="width: 100px; float: left;"&gt;Address:&lt;/span&gt; &lt;input type="text" name="address" /&gt;&lt;br /&gt;
          &lt;span style="width: 100px; float: left;"&gt;Postcode:&lt;/span&gt; &lt;input type="text" name="postcode" /&gt;&lt;br /&gt;
          &lt;span style="width: 100px; float: left;"&gt;Country:&lt;/span&gt; &lt;input type="text" name="country" /&gt;&lt;br /&gt;
          &lt;span style="width: 100px; float: left;"&gt;Telephone:&lt;/span&gt; &lt;input type="text" name="tel" /&gt;&lt;br /&gt;
          &lt;span style="width: 100px; float: left;"&gt;Email:&lt;/span&gt; &lt;input type="text" name="email" /&gt;
      &lt;/p&gt;
  
      &lt;input name="calcButton" onClick="calculate(this.form)" value="Calculate Total" type="button"&gt; Total: &amp;pound; &lt;input type="text" name="amount" value="6.98" /&gt;
      &lt;input value="Checkout" onClick="calculate(this.form)" type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>