I have a html page that sends a HTTP POST to a php page, and have embedded a JSON object as a parameter. When I try to retrieve the parameters, however, I can only retrieve “pass” and nothing else. Am I missing something about parsing JSON in php??
html POST form:
<form method="POST" action="......../username_exist.php" >
<input type="hidden" name="param" value='{"username":"user123","pass":"147852369qwerfdsazxcv","funny":"funny"}' />
<input type="submit" value="Click Me to submit" />
</form>
and the php page:
$param = json_decode($_POST['param']);
$username = $param['username'];
$pass = $param['pass'];
$funny = $param['funny'];
echo $pass;
echo $username;
echo $funny;
give the result of:
147852369qwerfdsazxcv
From what I’ve read from PHP Docs, calling
json_decodewithoutassocparam will return an object, so you need to access its property like$param->pass,$param->username.Cheers!