Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following PHP script for in-app purchase verification for an iPhone app. However, the script (from chrismaddern) runs effectively on localhost (mac) and does not run or give any output on my actual server (Ubuntu 12). Here's the script:


function validateReceipt($receipt, $isSandbox = true)

if ($isSandbox) {
    $endpoint = '';
    print "Environment: Sandbox (use 'sandbox' URL argument to toggle)<br />";
else {
    $endpoint = '';
    print "Environment: Production (use 'sandbox' URL argument to toggle)<br />";

$postData = json_encode(
    array('receipt-data' => $receipt)

$ch = curl_init($endpoint);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

$response = curl_exec($ch);
$errno    = curl_errno($ch);
$errmsg   = curl_error($ch);

if ($errno != 0) {
    throw new Exception($errmsg, $errno);

$data = json_decode($response);

if (!is_object($data)) {
    throw new Exception('Invalid response data');

if (!isset($data->status) 
|| $data->status != 0) 
    print 'Status Code: '. $data->status . '<br/>';
    throw new Exception('Invalid receipt');

return array(
    'quantity'       =>  $data->receipt->quantity,
    'product_id'     =>  $data->receipt->product_id,
    'transaction_id' =>  $data->receipt->transaction_id,
    'purchase_date'  =>  $data->receipt->purchase_date,
    'app_item_id'    =>  $data->receipt->app_item_id,
    'bid'            =>  $data->receipt->bid,
    'bvrs'           =>  $data->receipt->bvrs

$receipt   = $_GET['receipt'];
$isSandbox = (bool) $_GET['sandbox'];

try {
$receipt = base64_encode($receipt);
$info = validateReceipt($receipt, $isSandbox);
echo 'Success';
//echo $info;
catch (Exception $ex) {
echo $ex->getMessage().'<br />';

I'm passing the receipt in base64 manually for testing purposes and here's what I'm getting in both the cases:

On LocalHost: Environment: Production (use 'sandbox' URL argument to toggle) Success

On Actual Server: Environment: Production (use 'sandbox' URL argument to toggle)

As you can see, there's no output on the actual server. The server OS is Ubuntu 12.04 and it runs PHP smoothly as my website and other app files have been running all this while.

So can anyone provide a solution ASAP!! Thanks ?>

share|improve this question

You need to turn on error reporting or check the error log to get the error message(s). Perhaps curl is not installed on the Ubuntu server?

share|improve this answer
cURL is installed. I checked that via man curl in terminal. And how do I turn on error reporting and where do I check the logs? Thanks – proctr Jul 16 '12 at 19:03
@proctr curl or php5-curl? The PHP curl library has to be installed (and enabled) in order to use the functions in PHP. The manpages come with the commandline client. – DerfK Jul 16 '12 at 19:53
yeah i have php5-curl installed. :( – proctr Jul 17 '12 at 6:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.