PHP example for the https://keyauth.cc authentication system.
If the default example not added to your software isn't functioning how it should, please join the Discord server https://discord.gg/keyauth and submit the issue in the #bugs
channel.
However, we do NOT provide support for adding KeyAuth to your project. If you can't figure this out you should use Google or YouTube to learn more about the programming language you want to sell a program in.
KeyAuth is licensed under Elastic License 2.0
-
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
-
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
-
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
Thank you for your compliance, we work hard on the development of KeyAuth and do not appreciate our copyright being infringed.
Please add a Cloudflare firewall rule to show challenge to users, then set challenge passage to 1 year so they don't have to frequently complete challenge
KeyAuth is an Open source authentication system with cloud hosting plans as well. Client SDKs available for C#, C++, Python, Java, JavaScript, VB.NET, PHP, Rust, Go, Lua, Ruby, and Perl. KeyAuth has several unique features such as memory streaming, webhook function where you can send requests to API without leaking the API, discord webhook notifications, ban the user securely through the application at your discretion. Feel free to join https://discord.gg/keyauth if you have questions or suggestions.
Visit https://keyauth.cc/app/ and select your application, then click on the PHP tab
It'll provide you with the code which you should replace with in the credentials.php
file.
$KeyAuthApp = new KeyAuth\api("appNameHere", "keyAuthOwnerIDHere");
You must call this function prior to using any other KeyAuth function. Otherwise the other KeyAuth function won't work.
$KeyAuthApp->init();
$numKeys = $_SESSION["numUsers"];
$numUsers = $_SESSION["numKeys"];
$numOnlineUsers = $_SESSION["numOnlineUsers"];
$customerPanelLink = $_SESSION["customerPanelLink"];
if ($KeyAuthApp->login("userNameHere", "passWordHere")) {
// send user to dashboard or wherever you prefer
}
if ($KeyAuthApp->register("userNameHere", "passWordHere", "licenseKeyHere")) {
// send user to dashboard or wherever you prefer
}
Used so the user can add extra time to their account by claiming new key.
Warning No password is needed to upgrade account. So, unlike login, register, and license functions - you should not log user in after successful upgrade.
if ($KeyAuthApp->upgrade("userNameHere", "licenseKeyHere")) {
// don't login, upgrade function is not for authentication, it's simply for redeeming keys
// make the user login with their username and password now.
}
Users can use this function if their license key has never been used before, and if it has been used before. So if you plan to just allow users to use keys, you can remove the login and register functions from your code.
if ($KeyAuthApp->license("licenseKeyHere")) {
// send user to dashboard or wherever you prefer
}
Show information for current logged-in user.
$username = $_SESSION["user_data"]["username"];
$subscriptions = $_SESSION["user_data"]["subscriptions"];
$subscription = $_SESSION["user_data"]["subscriptions"][0]->subscription;
$expiry = $_SESSION["user_data"]["subscriptions"][0]->expiry;
for ($i = 0; $i < count($subscriptions); $i++) {
echo "#" . $i + 1 . " Subscription: " . $subscriptions[$i]->subscription . " - Subscription Expires: " . "<script>document.write(convertTimestamp(" . $subscriptions[$i]->expiry . "));</script>";
}
If you want to wall off parts of your app to only certain users, you can have multiple subscriptions with different names. Then, when you create licenses that correspond to the level of that subscription, users who use those licenses will get a subscription with the name of the subscription that corresponds to the level of the license key they used.
if(findSubscription("default", $_SESSION["user_data"]["subscriptions"])) {
// user has subscription with name "default"
}
else {
// user does not have subscription with name "default"
}
A string that is kept on the server-side of KeyAuth. On the dashboard you can choose for each variable to be authenticated (only logged in users can access), or not authenticated (any user can access before login). These are global and static for all users, unlike User Variables which will be dicussed below this section.
//* Get Public Variable
$var = $KeyAuthApp->var("varName");
echo "Variable Data: " . $var;
User variables are strings kept on the server-side of KeyAuth. They are specific to users. They can be set on Dashboard in the Users tab, via SellerAPI, or via your loader using the code below. discord
is the user variable name you fetch the user variable by. test#0001
is the variable data you get when fetching the user variable.
//* Set Up User Variable
$KeyAuthApp->setvar("varName", "varData");
And here's how you fetch the user variable:
//* Get User Variable
$var = $KeyAuthApp->getvar("varName");
echo "Variable Data: " . $var;
Can be used to log data. Good for anti-debug alerts and maybe error debugging. If you set Discord webhook in the app settings of the Dashboard, it will send log messages to your Discord webhook rather than store them on site. It's recommended that you set Discord webhook, as logs on site are deleted 1 month after being sent.
You can use the log function before login & after login.
//* Log Something to the KeyAuth webhook that you have set up on app settings
$KeyAuthApp->log("message");