JSON Returning Null in PHP

Posted by kira423 on Stack Overflow See other posts from Stack Overflow or by kira423
Published on 2012-10-13T03:24:40Z Indexed on 2012/10/13 3:37 UTC
Read the original article Hit count: 205

Filed under:
|
|

Here is the two scripts I have

Script 1:

if(sha1($json+$secret) == $_POST['signature']) {
    $conversion_id = md5(($obj['amount']));
    echo "OK";
    echo $conversion_id;
    mysql_query("INSERT INTO completed (`id`,`uid`,`completedid`) VALUES ('','".$obj['uid']."','".$conversion_id."')");
} else {

}
?>

Script 2:

<?
$json = $_POST['payload'];
$secret = "78f12668216b562a79d46b170dc59f695070e532";
$obj = json_decode($json);

if(sha1($json+$secret) == $_POST['signature']) {
    print "OK";
} else {

}
?>

The problem here is that it is returning all NULL values. I am not an expert with JSON so I have no idea what is going on here. I really have no way of testing it because the information is coming from an outside website sending information such as this:

{
  payload: {
    uid: "900af657a65e",
    amount: 50,
    adjusted_amount: 25
  },
  signature: "4dd0f5da77ecaf88628967bbd91d9506"
}

The site allows me to test the script, but because json_decode is providing NULL values it will not get through the signature block.

Is there a way I can test it myself? Or is there a simple error in this script that I may have just looked over?

© Stack Overflow or respective owner

Related posts about php

Related posts about JSON