#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    47
    Rep Power
    3

    Parse JSON from POST


    Yesterday I posted an issue I was having parsing the JSON from a URL and I was using the GET method. Now that I am able to verify the functionality and use the variables, I need to be able to accept that JSON string via POST and interact it with my PHP file.
    PHP Code:
    header('Content-type: application/json');
    if (
    get_magic_quotes_gpc()) {
        function 
    magicQuotes_awStripslashes(&$value$key) {$value stripslashes($value);}
        
    $gpc = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
        
    array_walk_recursive($gpc'magicQuotes_awStripslashes');
    }
    $string $_GET["string"];
    $json_a=json_decode($string,true);
    $username $json_a["username"];
    $secret_key $json_a["secret_key"];
    $password $json_a["password"];
    echo 
    'username= '.$username;
    echo 
    "\n";
    echo 
    'password= '.$password;
    echo 
    "\n";
    echo 
    'secret_key= ' .$secret_key;
    echo 
    "\n"
    I am not sure what I need to change the $string=_____ to. I was told...
    just "remove the string" param in the querystring so as it to be: url/jsonstring
    How would I test this by posting this json string to the PHP file? I know how to write a php form, just not sure how to send it as a json string.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,068
    Rep Power
    9398
    If it's in POST and not GET then use $_POST and not $_GET.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    47
    Rep Power
    3
    So just use
    PHP Code:
    $string $_POST 
    ??? I tried that, But it didnt work. I would like to test it but am unsure how to post a json string.

    What did he mean by....
    just "remove the string" param in the querystring so as it to be: url/jsonstring
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    What requinix said:
    If it's in POST and not GET then use $_POST and not $_GET.
    So find in your code where you see $_GET. Replace it with $_POST. Just replace those 5 characters with those 6 characters. That's it.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo