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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.