The Validate method
The validate method simply validates whether a User's Application Key is valid.
Basic usage
It can be used as follows:
<?php
$PHPingFM = new PHPingFM($developer_key, $user_api_key);
$validates = $PHPingFM->validate();
// The $validates variable contains a boolean, whether the API key validated or not.
?>
More advanced usage
A more complex example would be when tied with setUserAppKey - you could check a bunch of Application keys using the same object, as follows:
<?php
// The $user_api_key is optional.
$PHPingFM = new PHPingFM($developer_key);
// The user application keys to check:
$user_application_keys = array(
// The of the array are the application keys
// and the values are whether it validates or not.
"my user application key" => FALSE,
"your user application key" => FALSE,
);
// Iterate through all of them and check them
foreach ($user_application_keys as $key) {
// Set the User application key.
$PHPingFM->setUserApplicationKey($key);
$user_application_keys[$key] = $PHPingFM->validate();
}
?>
Try it out!
To try it out, simply enter an application key in the form below. Try entering both a valid one and an invalid one.The code behind that
This is the code used to generate this (of course the code we use is a little more complicated, because we have to deal with the "I don't have a key" case):
<?php
$PHPingFM = new PHPingFM($developer_key, $_POST['application_key']);
$result = $PHPingFM->validate();
if (!$result) {
$output = '<div class="error">User application key is invalid.</div>';
}
else {
$output = '<div class="success">User application key is valid.</div>';
}
?>