Jump to content

foreach ($_POST as $key=>$value)


danyfeg

Recommended Posts

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);

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.