danyfeg Posted June 16, 2017 Share Posted June 16, 2017 Hello, Below is a php code i am writing on an ubuntu server using VNC. as shown in the attached when i run the php code, its saying that newcontent is undefined. We figured out that the problem is related to the fact that the code is not entering the loop foreach ($_POST as $key=>$value). I would really appreciate your help. please note that the below code is used to validate apple IAP receipt through a dedicated server. <?php function getReceiptData($receipt) { $fh = fopen('showme.txt',w); fwrite($fh,$receipt); fclose($fh); $endpoint = 'https://sandbox.itunes.apple.com/verifyReceipt'; $ch = curl_init($endpoint); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $receipt); $response = curl_exec($ch); $errno = curl_errno($ch); $errmsg = curl_error($ch); curl_close($ch); $msg = $response.' - '.$errno.' - '.$errmsg; echo $response; } foreach ($_POST as $key=>$value){ $newcontent .= $key.' '.$value; } $new = trim($newcontent); $new = trim($newcontent); $new = str_replace('_','+',$new); $new = str_replace(' =','==',$new); if (substr_count($new,'=') == 0){ if (strpos('=',$new) === false){ $new .= '='; } } $new = '{"receipt-data":" '. $new ' "}'; $info = getReceiptData($new); ?> Quote Link to comment Share on other sites More sharing options...
kicken Posted June 16, 2017 Share Posted June 16, 2017 If it's not entering the loop then $_POST must be empty. Either the request to your script is not a POST request or no data was submitted. You can fix your undefined error by initializing $newcontent above the loop, but if you're expecting data you'll have to look into why you're not getting it. $newcontent = ''; foreach ($_POST as $key=>$value){ $newcontent .= $key.' '.$value; } side note: In the future, surround your code with tags when posting, it makes it easier to read and preserves spacing. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 16, 2017 Share Posted June 16, 2017 Also - you should always show the EXACT error message and the line number and POINT out to us where that line is. That could help in solving this very problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.