我在php和json中创建了一个用户ID白名单,但它不会工作所以它应该是这样的
{ "users": { "ANID": { "ANID": "true" },
"97594568": { "isvalid": "true" },
"ANID": { "isvalid": "true" },
"ANID": { "isvalid": "true" },
"ANID": { "isvalid": "true" },
"ANID": { "isvalid": "true" },
"ANID": { "isvalid": "true" } } }
如果你转到whitelist.php?uid = ANID它应该说成功,如果没有列入白名单,它应该说失败
答案 0 :(得分:0)
<强> whitelist.json:强>
{
"users": {
"0001": {
"isvalid": "true"
},
"0002": {
"isvalid": "true"
},
"0003": {
"isvalid": "true"
},
"0004": {
"isvalid": "true"
},
"0005": {
"isvalid": "true"
}
}
}
<强> whitelist.php 强>
<?php
$data = file_get_contents('whitelist.json');
$json = json_decode($data, true);
if (array_key_exists($_GET['uid'], $json['users'])) {
echo 'User is whitelisted';
} else {
echo 'User is NOT whitelisted';
}
whitelist.php?uid=0001
会返回User is whitelisted
whitelist.php?uid=0006
会返回User is NOT whitelisted