I am making a userid whitelist in php and json but it wont work so it should be like this
{ "users": { "ANID": { "ANID": "true" },
"97594568": { "isvalid": "true" },
"ANID": { "isvalid": "true" },
"ANID": { "isvalid": "true" },
"ANID": { "isvalid": "true" },
"ANID": { "isvalid": "true" },
"ANID": { "isvalid": "true" } } }
and if you go to whitelist.php?uid=ANID it should say succes and if not whitelisted it should say Failed
Use array_key_exists
:
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
would return User is whitelisted
whitelist.php?uid=0006
would return User is NOT whitelisted