Simple Customer and Api Protector - PHP
-
PxVision May 27, 2019Hi,
I maked the simple user, api system, create new file in your server and putting following code and save.
for validate user and api key, for example you can make a form on your product :
POST Method, eg:
<form method="post" action="FILE_URL">
<input type="text" name="user">
<input type="text" name="api">
<input type="hidden" name="product" value="simple">
</form>
======== PHP CODE =========
<?php
//Step One -> Define Your Product Name
$product = 'Simple';
//Step One -> Define Your Customers List
$customers = [
'Username-01',
'Username-02',
''
];
//Step Three -> Define Your Unique API Keys
$apikeys = [
'123',
'987',
''
];
//Step Four -> Get User Input values
$name = isset( $_REQUEST['product'] ) ? $_REQUEST['product'] : false; //product name
$user = isset( $_REQUEST['user'] ) ? $_REQUEST['user'] : false; //user name
$api = isset( $_REQUEST['api'] ) ? $_REQUEST['api'] : false; //api key
//Step Five -> Make the lowers values
$customers = array_map( 'strtolower', $customers );
$apikeys = array_map( 'strtolower', $apikeys );
$product = strtolower( $product );
$name = strtolower( $name );
$user = strtolower( $user );
$api = strtolower( $api );
//Step Six -> Check the user exists on buyer list
if( in_array( $user, $customers ) ) {
$validate_user = true;
}
else {
$validate_user = false;
}
//Step Seven -> Check the api exists on api list
if( in_array( $api, $apikeys ) ) {
$validate_api = true;
}
else {
$validate_api = false;
}
//Step Eight -> Validate User , Api and Product
if( $validate_user && $validate_api && $product == $name ) {
$status = true;
}
else {
$status = false;
}
//Step Nine -> Response in json format
exit( json_encode([ 'status' => $status ]) );
?> -
mrphp Aug 18, 2021Good idea friend , another one is to
1.Give Purchase Key To User After Buying
2. insert the purchase key in our database
3. When the user installs the script ask for license
4. If the key is present in our database grant the access else prohibit form installing -
NextMAS Aug 18, 2021Guys can you create a complete open source product licensing system...
-
mrphp Aug 18, 2021Yeah , I can
-
NextMAS Aug 18, 2021Thank you so much.