Blockland Forums > General Discussion
[Resource] Using the Blockland auth server with PHP
Subpixel:
First, you will need to insert this function into your PHP code:
--- Code: ---function BlocklandAuthenticate($username)
{
//Zapk 12270
$postdata = http_build_query(
array(
'NAME' => $username,
'IP' => $_SERVER['REMOTE_ADDR']
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://auth.blockland.us/authQuery.php', false, $context);
return $result;
}
--- End code ---
The function returns a string of the auth server's response.
[+]Usage
Say the user wants to register under the name "Badspot", and you want valid Blockland users only.
You would handle the string returned by BlocklandAuthenticate(username). In this case, username would be "Badspot".
It sends the username and the client's IP address to the auth server, where it checks to see if the IP has played under that username last.
If their IP address does not match Badspot's IP address (which is saved on the auth server), it will return incorrect. If it does, it will return correct.
[+]Correct
When correct, it will return "YES 0" where 0 is the user's Blockland ID.
[+]Incorrect
If it's incorrect, it will simply return "NO".
[/list]
Here is an example:
--- Code: ---$authstring = BlocklandAuthenticate($_POST['user_name']);
$autharray = explode(' ',trim($authstring));
if($autharray[0] == "YES")
{
$blid = $autharray[1];
//allow registration or whatever
}
else
{
//give them an error and deny registration
}
--- End code ---
Please note: the username is not case-sensitive.
Scriode:
This is useful, but shouldn't it belong in the coding section as a resource?
Subpixel:
--- Quote from: Scriode on January 21, 2014, 10:23:27 PM ---This is useful, but shouldn't it belong in the coding section as a resource?
--- End quote ---
It's not TorqueScript, so not really.
Scriode:
--- Quote from: Subpixel on January 21, 2014, 10:24:16 PM ---It's not TorqueScript, so not really.
--- End quote ---
No, I guess not. But more people in coding help would find it useful that people in general discussion? If you don't think so than that is okay too.
Subpixel:
Here is a demo:
http://zapkraft.net/tools/blockland-auth-demo.php