title: In App Purchase Server verification
body: <p>I'm currently trying to verify my In App Purchase Receipt with the AppStore using server side verification (in PHP).</p>
  
  <p>Here is my code:</p>
  
  <pre><code>// ViewController.m:
  NSString *receiptDataString = [[NSString alloc] initWithData:[transaction transactionReceipt] encoding:NSUTF8StringEncoding];
  NSString *verificationDataString = [NSString stringWithFormat:@"receiptData=%@", receiptDataString];
  NSData *verificationData = [NSData dataWithBytes:[verificationDataString UTF8String] length:[verificationDataString length]];
  
  NSMutableURLRequest *verificationRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://update.csundm.de/inapp/verifyReceipt.php"]];
  [verificationRequest setHTTPMethod:@"POST"];
  [verificationRequest setHTTPBody:verificationData];
  
  NSData *verificationResultData = [NSURLConnection sendSynchronousRequest:verificationRequest returningResponse:nil error:nil];
  NSString *verificationResultString = [[NSString alloc] initWithData:verificationResultData encoding:NSUTF8StringEncoding];
  NSLog(@"%@", verificationResultString);
  
  ********************************************************
  
  // verifyReceipt.php:
  $receiptData = $_POST["receiptData"];
  $receiptDataEncoded = base64_encode($receiptData);
  $receiptJSONString = json_encode(Array("receipt-data" =&gt; $receiptDataEncoded));
  
  $contextData = array ( 
                        "method" =&gt; "POST",
                        "header" =&gt; "Connection: close\r\n".
                        "Content-Length: ".strlen($receiptJSONString)."\r\n",
                        "content" =&gt; $receiptJSONString);
  $context = stream_context_create (array ( 'https' =&gt; $contextData ));
  $result =  file_get_contents ("https://sandbox.itunes.apple.com/verifyReceipt", false, $context);
  
  $jsonResult = json_decode($result);
  if ($jsonResult -&gt; {"status"} != 0) {
      echo "Receipt invalid: ".$result;
  }
  else {
      echo "Receipt valid";
  }
  </code></pre>
  
  <p>Unfortunately I'm getting »Receipt invalid: {"status":21000}« Can anybody imagine what the problem could be? I can't even find information about this error code on the internet. I found one error description but they said that this is only for non-renewable subscriptions.</p>
  
  <p>Thanks a lot, with kind regards, Julian</p>