Jump to content

Licensing Module Addon - Trial Account Addon


Idealws

Recommended Posts

Hello,

 

First I would like to say I like the new licensing addon. I had started working on integrating PHP Audit with WHMCS and never finished it as I got to busy. I am glad I never finished it as this new addon is easy to use and integrate as well as expand on.

 

With that said. I have created a function which will allow you to create trial accounts for your products. It is simple to add as it is a function you would put in your check license file or however you are using the current code. Basically this is how it works:

 

1. You enter the number of days you want the license to expire in.

2. Call the function using the date the script was registered and the expire days.

3. The function will return either FALSE which means it is past the days allotted or it will return the remaining days left.

4. From there you can either stop the script or show how many days there are left.

 

Here is the code and how to use it:

// Set the number os days until it expires
$licexpires = "15";

// Let's create a function that locks the system out
// for trial accounts based off the trial days
function check_trial($keydate,$expdays) {
// Lets get the reg date and format it as needed
list($syear,$smon,$sday) = explode("-", $keydate);
// Create the start date from the original reg date
$startdate = gregoriantojd($smon, $sday, $syear);
// Create the actual date so we can compair
$currdate = gregoriantojd(date("m"),date("d"), date("Y"));
// Lets see how many days it has been so far
$daysdiff = $currdate - $startdate;
// Lets see if there are any days left
$daysleft = $expdays - $daysdiff;
// Check if we are past the days expired
if($daysdiff > $expdays) {
	$expired = FALSE;
	// if past days expired return expired
	return $expired;
}else{
	// If not past expired days send days left
	return $daysleft;
}
}


// Lets check to see if the license is expired
$isexpired = check_trial($results['regdate'], $licexpires);

// If it is expired we need tro do something
if($isexpired == FALSE) {
// If expired print out error and exit script execution
echo "Your $licexpires day trial license is expired";
exit;

}else{
// If it is not expired lets print how many days are left
echo $isexpired;
}

 

The way I suggest using it is setup a new product with the license the Key prefix of say Trial15- then you can test it against only license that start that way. If your not sure how to do that you can check it like so:

$keyparts = explode("-", $results['licensekey']);

if($keyparts['0'] == "Trial15") {
// Process you trial checks here.

}

 

Hope this helps those of you who are using the new license module.

 

Please let me know if you have any questions about this little hack.

 

Best Regards,

Ray

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated