#21 - Code for a simple XLM Stellar Federation Server in PHP
Data: 2018-08-11 12:00 - PHP
Allows you to create a simple XLM Stellar Federation Server in PHP.
function error($err, $code = 400) {
http_response_code($code);
if ($err != '')
echo json_encode(['detail' => $err]);
exit();
}
$accounts = [
'test*andrebaltazar.com' => [
'stellar_address' => 'test*andrebaltazar.com',
'account_id' => 'GA3RSGCBA6NN2ASDPXQUK4SW43XJ4RJ3BPAF27HMCCKDXJWEMNX4FT64',
],
'test2*andrebaltazar.com' => [
'stellar_address' => 'test2*andrebaltazar.com',
'account_id' => 'GA3RSGCBA6NN2ASDPXQUK4SW43XJ4RJ3BPAF27HMCCKDXJWEMNX4FT64',
],
];
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');
if (!array_key_exists('q', $_GET) || !array_key_exists('type', $_GET))
error('Expected parameters q and type.');
if ($_GET['type'] == 'name') {
$nameLookup = strtolower($_GET['q']);
if (!array_key_exists($nameLookup, $accounts))
error('No record found.', 404);
echo json_encode($accounts[$nameLookup]);
} else {
error('Unsupported type.');
}
// Don't forget to add '.well-known/stellar.toml' with the contents:
// FEDERATION_SERVER="https://yourwebsite/this_script.php"