我有一个 json 表单字段,其中有一个编码为复选框:
{"name":"Act","description":"Checkthis","type":"checkbox"}
谁能告诉我 如果使用 php检查它,如何获取此复选框的此值
这是表格:
<iframe src='http://www.facebook.com/plugins/registration.php?
client_id=360&
redirect_uri=http://www.pingcampus.com/facebook_registration_plugin/store_user_data.php&
fields=[
{"name":"name"},
{"name":"email"},
{"name":"gender"},
{"name":"birthday"},
{"name":"captcha"},
{"name":"Act","description":"Checkthis","type":"checkbox"}
]'
scrolling="auto"
frameborder="no"
style="border:none"
allowTransparency="true"
width="500"
height="600">
</iframe>
这是PHP代码:
<?php
define('FACEBOOK_APP_ID', '');
define('FACEBOOK_SECRET', '');
// No need to change function body
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
if ($_REQUEST) {
$response = parse_signed_request($_REQUEST['signed_request'],
FACEBOOK_SECRET);
/*
echo "<pre>";
print_r($response);
echo "</pre>"; // Uncomment this for printing the response Array
*/
echo $_POST["Act"];
$name = $response["registration"]["name"];
$email = $response["registration"]["email"];
$password = $response["registration"]["password"];
$gender = $response["registration"]["gender"];
$dob = $response["registration"]["birthday"];
$phone = $response["registration"]["phone"];
$act1 = $response["registration"]["Act"];
// Connecting to Database
mysql_connect('', '', '') or die(mysql_error());
mysql_select_db('pingcampus');
$result = mysql_query("INSERT INTO usxxx set
name='$name',
email='$email',
gender='$gender',
act='$act'
");
if ($result) {
// User successfully stored
// Redirect to some page
} else {
echo mysql_error();
// Redirect to error page
}
} else {
echo '$_REQUEST is empty';
}
?>