PDA

View Full Version : Confusion about localkey



mrl14
07-06-12, 05:52 AM
Does anyone understand how to implement the local key? I'm a little confused by it and the documentation isn't clear.

I've copied the sample code into my plugin and I've set the $licensekey to equal the licensekey field on the setup page. However, the $localkey I have no idea what to do with this. Any ideas? thx

peterruiter
07-08-12, 01:31 PM
The localkey is just a hashed array of your license data.
If the localkey is valid then you don't have to check remotely if the license data is still valid.

If you need more info or pointers on how to implement this, please post your bit of code here within PHP tags so we can help you.
You may also pm me with your code and I'm sure I can help you out.

mrl14
07-08-12, 08:11 PM
Here is what my code looks like, but as I said my confusion is what do I do with this local key. I've stored it into a db, but beyond that I don't know if I'm supposed to call it and compare it to something or what not.





//include license check function
include "licensecheck.php";


function addonsample_config() {
//standard config code
}


function addonsample_activate() {
//standard activate code
}

function addonsample_deactivate() {
//standard deactivate code
}

function addonsample_output() {
//output code

//Retrieve LicenseKey
$licensekey = $vars['license'];

//retrieve local key from db (THIS IS WHERE I'M CONFUSED…DO I EVEN NEED TO RETRIEVE IT? IF SO WHY?)
//$query = "SELECT localkey FROM `mod_database`";
//$result = mysql_query($query);
//$row = mysql_fetch_assoc($result);
//$localkey = $row['localkey'];

// The call below actually performs the license check. You need to pass in the license key and the local key data
$results = check_license($licensekey,$localkey);

// For Debugging, Echo Results
//echo "<textarea cols=100 rows=20>"; print_r($results); echo "</textarea>";

if ($results["status"]=="Active")
{
# Allow Script to Run
if ($results["localkey"])
{
# Save Updated Local Key to DB or File
$localkeydata = $results["localkey"];
$query = "INSERT INTO mod_database (localkey) VALUES('$localkeydata')";
$result = mysql_query($query) or die("Error adding localkey " . mysql_error());
}

//MY MODULES CODE GOES HERE

} elseif ($results["status"]=="Invalid") {
# Show Invalid Message
print "Your license is invalid";
} elseif ($results["status"]=="Expired") {
# Show Expired Message
print "Your license has expired";
} elseif ($results["status"]=="Suspended") {
# Show Suspended Message
print "Your license has been suspended";
}





}

alaali
07-08-12, 08:29 PM
As you can see at :
check_license($licensekey,$localkey) If you have a local key stored you can use it on this function call. if you did the function will check the local key and if it is valid it will not call the licensing server. This will make your application faster as it will not always call your server to check if this is a valid license, and also will lower the load on your server as the calls to your server will be less. The application will work also even if your server is down if the local key is valid.

mrl14
07-08-12, 10:48 PM
So what you're saying is that what I have done is correct. I should uncomment the call to retrieve the local key so that the script doesn't ping my server? Otherwise, if I don't store the local key, it'll ping my server every time?

peterruiter
07-09-12, 08:08 AM
So what you're saying is that what I have done is correct. I should uncomment the call to retrieve the local key so that the script doesn't ping my server? Otherwise, if I don't store the local key, it'll ping my server every time?

Yes that is correct.