Lui2004 Posted December 2, 2015 Author Share Posted December 2, 2015 (edited) I Have installed whmcs in var/www/html/ So my $whmcsurl is : $whmcsurl = 'http://ipfromserver/'; He correct directory to check is : /home/test/test1/ Edited December 2, 2015 by Lui2004 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 2, 2015 Author Share Posted December 2, 2015 thats my check_code.php <?php /** * WHMCS Licensing Addon - Integration Code Sample * http://www.whmcs.com/addons/licensing-addon/ * * The following code is a fully working code sample demonstrating how to * perform license checks using the WHMCS Licensing Addon. It is PHP 4 and * 5 compatible. Requires the WHMCS Licensing Addon to be used. * * @package WHMCS * @author WHMCS Limited <development@whmcs.com> * @copyright Copyright (c) WHMCS Limited 2005-2014 * @license http://www.whmcs.com/license/ WHMCS Eula * @version $Id$ * @link http://www.whmcs.com/ */ /** * This is just example code, and is not intended to be invoked directly. * * To ensure this code isn't unintentionally invoked on the command line or * via the web interface, any attempt to actually execute this code will * be exited: */ /** * If you are using this file as a template for your own module, once * you've modified the code for your use, remove the exit above. */ // Replace "yourprefix" with your own unique prefix to avoid conflicts with // other instances of the licensing addon included within the same scope function check_license($licensekey,$localkey='') { // ----------------------------------- // -- Configuration Values -- // ----------------------------------- // Enter the url to your WHMCS installation here $whmcsurl = 'http://ip from server/'; // Must match what is specified in the MD5 Hash Verification field // of the licensing product that will be used with this check. $licensing_secret_key = 'secret key from licensing addon'; // The number of days to wait between performing remote license checks $localkeydays = 15; // The number of days to allow failover for after local key expiry $allowcheckfaildays = 5; // ----------------------------------- // -- Do not edit below this line -- // ----------------------------------- $check_token = time() . md5(mt_rand(1000000000, 9999999999) . $licensekey); $checkdate = date("Ymd"); $domain = $_SERVER['SERVER_NAME']; $usersip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; $dirpath = dirname(__FILE__); $verifyfilepath = 'modules/servers/licensing/verify.php'; $localkeyvalid = false; if ($localkey) { $localkey = str_replace("\n", '', $localkey); # Remove the line breaks $localdata = substr($localkey, 0, strlen($localkey) - 32); # Extract License Data $md5hash = substr($localkey, strlen($localkey) - 32); # Extract MD5 Hash if ($md5hash == md5($localdata . $licensing_secret_key)) { $localdata = strrev($localdata); # Reverse the string $md5hash = substr($localdata, 0, 32); # Extract MD5 Hash $localdata = substr($localdata, 32); # Extract License Data $localdata = base64_decode($localdata); $localkeyresults = unserialize($localdata); $originalcheckdate = $localkeyresults['checkdate']; if ($md5hash == md5($originalcheckdate . $licensing_secret_key)) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $localkeydays, date("Y"))); if ($originalcheckdate > $localexpiry) { $localkeyvalid = true; $results = $localkeyresults; $validdomains = explode(',', $results['validdomain']); if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } $validips = explode(',', $results['validip']); if (!in_array($usersip, $validips)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } $validdirs = explode(',', $results['validdirectory']); if (!in_array($dirpath, $validdirs)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } } } } } if (!$localkeyvalid) { $responseCode = 0; $postfields = array( 'licensekey' => $licensekey, 'domain' => $domain, 'ip' => $usersip, 'dir' => $dirpath, ); if ($check_token) $postfields['check_token'] = $check_token; $query_string = ''; foreach ($postfields AS $k=>$v) { $query_string .= $k.'='.urlencode($v).'&'; } if (function_exists('curl_exec')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $whmcsurl . $verifyfilepath); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } else { $responseCodePattern = '/^HTTP\/\d+\.\d+\s+(\d+)/'; $fp = @fsockopen($whmcsurl, 80, $errno, $errstr, 5); if ($fp) { $newlinefeed = "\r\n"; $header = "POST ".$whmcsurl . $verifyfilepath . " HTTP/1.0" . $newlinefeed; $header .= "Host: ".$whmcsurl . $newlinefeed; $header .= "Content-type: application/x-www-form-urlencoded" . $newlinefeed; $header .= "Content-length: ".@strlen($query_string) . $newlinefeed; $header .= "Connection: close" . $newlinefeed . $newlinefeed; $header .= $query_string; $data = $line = ''; @stream_set_timeout($fp, 20); @fputs($fp, $header); $status = @socket_get_status($fp); while (!@feof($fp)&&$status) { $line = @fgets($fp, 1024); $patternMatches = array(); if (!$responseCode && preg_match($responseCodePattern, trim($line), $patternMatches) ) { $responseCode = (empty($patternMatches[1])) ? 0 : $patternMatches[1]; } $data .= $line; $status = @socket_get_status($fp); } @fclose ($fp); } } if ($responseCode != 200) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y"))); if ($originalcheckdate > $localexpiry) { $results = $localkeyresults; } else { $results = array(); $results['/'] = "Invalid"; $results['description'] = "Remote Check Failed"; return $results; } } else { preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $matches); $results = array(); foreach ($matches[1] AS $k=>$v) { $results[$v] = $matches[2][$k]; } } if (!is_array($results)) { die("Invalid License Server Response"); } if ($results['md5hash']) { if ($results['md5hash'] != md5($licensing_secret_key . $check_token)) { $results['status'] = "Invalid"; $results['description'] = "MD5 Checksum Verification Failed"; return $results; } } if ($results['status'] == "Active") { $results['checkdate'] = $checkdate; $data_encoded = serialize($results); $data_encoded = base64_encode($data_encoded); $data_encoded = md5($checkdate . $licensing_secret_key) . $data_encoded; $data_encoded = strrev($data_encoded); $data_encoded = $data_encoded . md5($data_encoded . $licensing_secret_key); $data_encoded = wordwrap($data_encoded, 80, "\n", true); $results['localkey'] = $data_encoded; } $results['remotecheck'] = true; } unset($postfields,$data,$matches,$whmcsurl,$licensing_secret_key,$checkdate,$usersip,$localkeydays,$allowcheckfaildays,$md5hash); return $results; } // Get the license key and local key from storage // These are typically stored either in flat files or an SQL database $licensekey = ""; $localkey = ""; $base = __DIR__; $handle = fopen($base."/license.txt", "r"); if ($handle) { $count = 0; while (($line = fgets($handle)) !== false) { // process the line read. if ($count == 0) { $licensekey = trim($line); } else if ($count == 1) { $localkey = trim($line); break; } $count++; } fclose($handle); } else { die("Could not read license file. Please contact support."); } echo $licensekey."<br/>"; echo $localkey."<br/>"; // Validate the license key information $results = check_license($licensekey, $localkey); // Raw output of results for debugging purpose echo '<textarea cols="100" rows="20">' . print_r($results, true) . '</textarea>'; // Interpret response switch ($results['status']) { case "Active": // get new local key and save it somewhere $localkeydata = str_replace(' ','',preg_replace('/\s+/', ' ', $results['localkey'])); $handle = fopen($base."/license.txt", "r"); if ($handle) { $count = 0; while (($line = fgets($handle)) !== false) { // process the line read. if ($count == 0) { $licence_key = trim($line); break; } $count++; } fclose($handle); if (isset($results['localkey'])) { $textfile = fopen($base . "/license.txt", "w") or die("Unable to open file!"); $contents = $licence_key . "\n" . $localkeydata . "\n"; fwrite($textfile, $contents); fclose($textfile); } } else { die("Could not read license file. Please contact support."); } break; case "Invalid": die("License key is Invalid"); break; case "Expired": die("License key is Expired"); break; case "Suspended": die("License key is Suspended"); break; default: die("Invalid Response"); break; } 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 2, 2015 Share Posted December 2, 2015 OK, if you go to "Your IP from Server" does this take you to the default page for WHMCS? For v6 this is the "Portal Home". 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 2, 2015 Author Share Posted December 2, 2015 yes if i enter the ip only i got to the "Portal Home" 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 2, 2015 Share Posted December 2, 2015 The license check you are running, is the server and this test check both located on the same server? 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 2, 2015 Author Share Posted December 2, 2015 (edited) 1.Server whmcs and script who i want try with the licensing addon i have try with 2 Server like whmcs+ licensing addon = 111.111.111.111 i get all like valid ip - Domain and Directory from the Server with whmcs and not from the other Server with the script and entered licens 2.Server and script = 222.222.222.222 but still the same licens not valid EDIT: which part from my check_code i must insert into my script for licensing ? Edited December 2, 2015 by Lui2004 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 2, 2015 Share Posted December 2, 2015 The whole check_sample_code.php is used for your license validation, the last part (if else statement of return status) is used for determining what to do when it encounters an invalid, inactive or suspended license. 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 2, 2015 Author Share Posted December 2, 2015 thanks but can you give me an example with my check_code.php? what i insert in my script ? 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 2, 2015 Share Posted December 2, 2015 /** * WHMCS Licensing Addon - Integration Code Sample * http://www.whmcs.com/addons/licensing-addon/ * * The following code is a fully working code sample demonstrating how to * perform license checks using the WHMCS Licensing Addon. It is PHP 4 and * 5 compatible. Requires the WHMCS Licensing Addon to be used. * * @package WHMCS * @author WHMCS Limited <development@whmcs.com> * @copyright Copyright (c) WHMCS Limited 2005-2014 * @license http://www.whmcs.com/license/ WHMCS Eula * @version $Id$ * @link http://www.whmcs.com/ */ function yourprefix123_check_license($licensekey, $localkey='') { // ----------------------------------- // -- Configuration Values -- // ----------------------------------- // Enter the url to your WHMCS installation here $whmcsurl = 'http://www.yourdomain.com/whmcs/'; // Must match what is specified in the MD5 Hash Verification field // of the licensing product that will be used with this check. $licensing_secret_key = 'abc123'; // The number of days to wait between performing remote license checks $localkeydays = 15; // The number of days to allow failover for after local key expiry $allowcheckfaildays = 5; // ----------------------------------- // -- Do not edit below this line -- // ----------------------------------- $check_token = time() . md5(mt_rand(1000000000, 9999999999) . $licensekey); $checkdate = date("Ymd"); $domain = $_SERVER['SERVER_NAME']; $usersip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; $dirpath = dirname(__FILE__); $verifyfilepath = 'modules/servers/licensing/verify.php'; $localkeyvalid = false; if ($localkey) { $localkey = str_replace("\n", '', $localkey); # Remove the line breaks $localdata = substr($localkey, 0, strlen($localkey) - 32); # Extract License Data $md5hash = substr($localkey, strlen($localkey) - 32); # Extract MD5 Hash if ($md5hash == md5($localdata . $licensing_secret_key)) { $localdata = strrev($localdata); # Reverse the string $md5hash = substr($localdata, 0, 32); # Extract MD5 Hash $localdata = substr($localdata, 32); # Extract License Data $localdata = base64_decode($localdata); $localkeyresults = unserialize($localdata); $originalcheckdate = $localkeyresults['checkdate']; if ($md5hash == md5($originalcheckdate . $licensing_secret_key)) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $localkeydays, date("Y"))); if ($originalcheckdate > $localexpiry) { $localkeyvalid = true; $results = $localkeyresults; $validdomains = explode(',', $results['validdomain']); if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } $validips = explode(',', $results['validip']); if (!in_array($usersip, $validips)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } $validdirs = explode(',', $results['validdirectory']); if (!in_array($dirpath, $validdirs)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } } } } } if (!$localkeyvalid) { $responseCode = 0; $postfields = array( 'licensekey' => $licensekey, 'domain' => $domain, 'ip' => $usersip, 'dir' => $dirpath, ); if ($check_token) $postfields['check_token'] = $check_token; $query_string = ''; foreach ($postfields AS $k=>$v) { $query_string .= $k.'='.urlencode($v).'&'; } if (function_exists('curl_exec')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $whmcsurl . $verifyfilepath); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } else { $responseCodePattern = '/^HTTP\/\d+\.\d+\s+(\d+)/'; $fp = @fsockopen($whmcsurl, 80, $errno, $errstr, 5); if ($fp) { $newlinefeed = "\r\n"; $header = "POST ".$whmcsurl . $verifyfilepath . " HTTP/1.0" . $newlinefeed; $header .= "Host: ".$whmcsurl . $newlinefeed; $header .= "Content-type: application/x-www-form-urlencoded" . $newlinefeed; $header .= "Content-length: ".@strlen($query_string) . $newlinefeed; $header .= "Connection: close" . $newlinefeed . $newlinefeed; $header .= $query_string; $data = $line = ''; @stream_set_timeout($fp, 20); @fputs($fp, $header); $status = @socket_get_status($fp); while (!@feof($fp)&&$status) { $line = @fgets($fp, 1024); $patternMatches = array(); if (!$responseCode && preg_match($responseCodePattern, trim($line), $patternMatches) ) { $responseCode = (empty($patternMatches[1])) ? 0 : $patternMatches[1]; } $data .= $line; $status = @socket_get_status($fp); } @fclose ($fp); } } if ($responseCode != 200) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y"))); if ($originalcheckdate > $localexpiry) { $results = $localkeyresults; } else { $results = array(); $results['status'] = "Invalid"; $results['description'] = "Remote Check Failed"; return $results; } } else { preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $matches); $results = array(); foreach ($matches[1] AS $k=>$v) { $results[$v] = $matches[2][$k]; } } if (!is_array($results)) { die("Invalid License Server Response"); } if ($results['md5hash']) { if ($results['md5hash'] != md5($licensing_secret_key . $check_token)) { $results['status'] = "Invalid"; $results['description'] = "MD5 Checksum Verification Failed"; return $results; } } if ($results['status'] == "Active") { $results['checkdate'] = $checkdate; $data_encoded = serialize($results); $data_encoded = base64_encode($data_encoded); $data_encoded = md5($checkdate . $licensing_secret_key) . $data_encoded; $data_encoded = strrev($data_encoded); $data_encoded = $data_encoded . md5($data_encoded . $licensing_secret_key); $data_encoded = wordwrap($data_encoded, 80, "\n", true); $results['localkey'] = $data_encoded; } $results['remotecheck'] = true; } unset($postfields,$data,$matches,$whmcsurl,$licensing_secret_key,$checkdate,$usersip,$localkeydays,$allowcheckfaildays,$md5hash); return $results; } // Get the license key and local key from storage // These are typically stored either in flat files or an SQL database $licensekey = "WHMCS-c5adf50c9a"; $localkey = '9tjIxIzNwgDMwIjI6gjOztjIlRXYkt2Ylh2YioTO6M3OicmbpNnblNWasx1cyVmdyV2ccNXZsVHZv1GX zNWbodHXlNmc192czNWbodHXzN2bkRHacBFUNFEWcNHduVWb1N2bExFd0FWTcNnclNXVcpzQioDM4ozc 7ISey9GdjVmcpRGZpxWY2JiO0EjOztjIx4CMuAjL3ITMioTO6M3OiAXaklGbhZnI6cjOztjI0N3boxWY j9Gbuc3d3xCdz9GasF2YvxmI6MjM6M3Oi4Wah12bkRWasFmdioTMxozc7ISeshGdu9WTiozN6M3OiUGb jl3Yn5WasxWaiJiOyEjOztjI3ATL4ATL4ADMyIiOwEjOztjIlRXYkVWdkRHel5mI6ETM6M3OicDMtcDM tgDMwIjI6ATM6M3OiUGdhR2ZlJnI6cjOztjIlNXYlxEI5xGa052bNByUD1ESXJiO5EjOztjIl1WYuR3Y 1R2byBnI6ETM6M3OicjI6EjOztjIklGdjVHZvJHcioTO6M3Oi02bj5ycj1Ga3BEd0FWbioDNxozc7ICb pFWblJiO1ozc7IyUD1ESXBCd0FWTioDMxozc7ISZtFmbkVmclR3cpdWZyJiO0EjOztjIlZXa0NWQiojN 6M3OiMXd0FGdzJiO2ozc7pjMxoTY8baca0885830a33725148e94e693f3f073294c0558d38e31f844 c5e399e3c16a'; // Validate the license key information $results = yourprefix123_check_license($licensekey, $localkey); // Raw output of results for debugging purpose echo '<textarea cols="100" rows="20">' . print_r($results, true) . '</textarea>'; // Interpret response switch ($results['status']) { case "Active": // get new local key and save it somewhere $localkeydata = $results['localkey']; break; case "Invalid": die("License key is Invalid"); break; case "Expired": die("License key is Expired"); break; case "Suspended": die("License key is Suspended"); break; default: die("Invalid Response"); break; } This example code is available to anyone running WHMCS in /whmcs/modules/servers/licensing/check_sample_code.php Here is some additional help from a guy who posted a great tutorial a few years ago: http://markustenghamn.com/configure-setup-whmcs-licensing-addon Please note that you need to update the value for $licensekey and you can leave $localkey blank until you get everything working. $localkey is explained in another tutorial but lets get the basics set and working for you first. 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 2, 2015 Author Share Posted December 2, 2015 (edited) ok thanks in which file i must integrate the check_sample_code.php ? i will Report tommorow Edited December 2, 2015 by Lui2004 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 2, 2015 Share Posted December 2, 2015 No problem, hope it helps. 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 3, 2015 Author Share Posted December 3, 2015 (edited) hi in my installscript i have follow: echo "\n##############################\n"; echo "# #\n"; echo "# Test-Script #\n"; echo "##############################\n\n"; echo " TEST\n\n"; do { echo "[*] Enter the License for installation: "; fscanf( STDIN, '%s', $licenza); } while ( ! is_valid_licence( $licenza) ); for mysql: mysql_query( "UPDATE `licence` SET `licenza` = '$licenza" ); and function: function is_valid_licence( $licenza) my actual check_code.php <?php function is_valid_licence($licenza, $localkey='') { // ----------------------------------- // -- Configuration Values -- // ----------------------------------- // Enter the url to your WHMCS installation here $whmcsurl = 'http://ip from server/'; // Must match what is specified in the MD5 Hash Verification field // of the licensing product that will be used with this check. $licensing_secret_key = 'key from licensing addon'; // The number of days to wait between performing remote license checks $localkeydays = 15; // The number of days to allow failover for after local key expiry $allowcheckfaildays = 5; // ----------------------------------- // -- Do not edit below this line -- // ----------------------------------- $check_token = time() . md5(mt_rand(1000000000, 9999999999) . $licensekey); $checkdate = date("Ymd"); $domain = $_SERVER['SERVER_NAME']; $usersip = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; $dirpath = dirname(__FILE__); $verifyfilepath = 'modules/servers/licensing/verify.php'; $localkeyvalid = false; if ($localkey) { $localkey = str_replace("\n", '', $localkey); # Remove the line breaks $localdata = substr($localkey, 0, strlen($localkey) - 32); # Extract License Data $md5hash = substr($localkey, strlen($localkey) - 32); # Extract MD5 Hash if ($md5hash == md5($localdata . $licensing_secret_key)) { $localdata = strrev($localdata); # Reverse the string $md5hash = substr($localdata, 0, 32); # Extract MD5 Hash $localdata = substr($localdata, 32); # Extract License Data $localdata = base64_decode($localdata); $localkeyresults = unserialize($localdata); $originalcheckdate = $localkeyresults['checkdate']; if ($md5hash == md5($originalcheckdate . $licensing_secret_key)) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $localkeydays, date("Y"))); if ($originalcheckdate > $localexpiry) { $localkeyvalid = true; $results = $localkeyresults; $validdomains = explode(',', $results['validdomain']); if (!in_array($_SERVER['SERVER_NAME'], $validdomains)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } $validips = explode(',', $results['validip']); if (!in_array($usersip, $validips)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } $validdirs = explode(',', $results['validdirectory']); if (!in_array($dirpath, $validdirs)) { $localkeyvalid = false; $localkeyresults['status'] = "Invalid"; $results = array(); } } } } } if (!$localkeyvalid) { $responseCode = 0; $postfields = array( 'licensekey' => $licensekey, 'domain' => $domain, 'ip' => $usersip, 'dir' => $dirpath, ); if ($check_token) $postfields['check_token'] = $check_token; $query_string = ''; foreach ($postfields AS $k=>$v) { $query_string .= $k.'='.urlencode($v).'&'; } if (function_exists('curl_exec')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $whmcsurl . $verifyfilepath); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } else { $responseCodePattern = '/^HTTP\/\d+\.\d+\s+(\d+)/'; $fp = @fsockopen($whmcsurl, 80, $errno, $errstr, 5); if ($fp) { $newlinefeed = "\r\n"; $header = "POST ".$whmcsurl . $verifyfilepath . " HTTP/1.0" . $newlinefeed; $header .= "Host: ".$whmcsurl . $newlinefeed; $header .= "Content-type: application/x-www-form-urlencoded" . $newlinefeed; $header .= "Content-length: ".@strlen($query_string) . $newlinefeed; $header .= "Connection: close" . $newlinefeed . $newlinefeed; $header .= $query_string; $data = $line = ''; @stream_set_timeout($fp, 20); @fputs($fp, $header); $status = @socket_get_status($fp); while (!@feof($fp)&&$status) { $line = @fgets($fp, 1024); $patternMatches = array(); if (!$responseCode && preg_match($responseCodePattern, trim($line), $patternMatches) ) { $responseCode = (empty($patternMatches[1])) ? 0 : $patternMatches[1]; } $data .= $line; $status = @socket_get_status($fp); } @fclose ($fp); } } if ($responseCode != 200) { $localexpiry = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - ($localkeydays + $allowcheckfaildays), date("Y"))); if ($originalcheckdate > $localexpiry) { $results = $localkeyresults; } else { $results = array(); $results['status'] = "Invalid"; $results['description'] = "Remote Check Failed"; return $results; } } else { preg_match_all('/<(.*?)>([^<]+)<\/\\1>/i', $data, $matches); $results = array(); foreach ($matches[1] AS $k=>$v) { $results[$v] = $matches[2][$k]; } } if (!is_array($results)) { die("Invalid License Server Response"); } if ($results['md5hash']) { if ($results['md5hash'] != md5($licensing_secret_key . $check_token)) { $results['status'] = "Invalid"; $results['description'] = "MD5 Checksum Verification Failed"; return $results; } } if ($results['status'] == "Active") { $results['checkdate'] = $checkdate; $data_encoded = serialize($results); $data_encoded = base64_encode($data_encoded); $data_encoded = md5($checkdate . $licensing_secret_key) . $data_encoded; $data_encoded = strrev($data_encoded); $data_encoded = $data_encoded . md5($data_encoded . $licensing_secret_key); $data_encoded = wordwrap($data_encoded, 80, "\n", true); $results['localkey'] = $data_encoded; } $results['remotecheck'] = true; } unset($postfields,$data,$matches,$whmcsurl,$licensing_secret_key,$checkdate,$usersip,$localkeydays,$allowcheckfaildays,$md5hash); return $results; } // Get the license key and local key from storage // These are typically stored either in flat files or an SQL database $licenza = ""; $localkey = ''; // Validate the license key information $results = is_valid_licence($licenza, $localkey); // Raw output of results for debugging purpose echo '<textarea cols="100" rows="20">' . print_r($results, true) . '</textarea>'; // Interpret response switch ($results['status']) { case "Active": // get new local key and save it somewhere $localkeydata = $results['localkey']; break; case "Invalid": die("License key is Invalid"); break; case "Expired": die("License key is Expired"); break; case "Suspended": die("License key is Suspended"); break; default: die("Invalid Response"); break; } do i Need Change somthing else ? regards Edited December 3, 2015 by Lui2004 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 3, 2015 Author Share Posted December 3, 2015 thats a screenshot in whmcs i got everytime Domain invalid thanks to all for help and pacienc 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 4, 2015 Share Posted December 4, 2015 Is the domain your PHP script on an IDN domain, is it just an IP address, or normal .com, .net etc? === Edit === Update: Sorry for the late response. 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 4, 2015 Author Share Posted December 4, 2015 its just ip without Domain no Problem mate youre the only one who trys to help me 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 4, 2015 Share Posted December 4, 2015 Well man to be honest I am not sure what it is right off. I am assuming your WHMCS license is license to your server IP address and not any domain? If so I would open up a support ticket with WHMCS. There is a few behind the scenes things they be be able to look at once they log intou your installations but it sounds like you have everything setup right. Sorry I can't be of more assistance to you but if you are able to find the answer through them or someone else I would love to know what it is. 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 4, 2015 Author Share Posted December 4, 2015 ok will do this thank for your time mate 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 4, 2015 Share Posted December 4, 2015 Glad to at least try and help! 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 4, 2015 Author Share Posted December 4, 2015 Hi little question My Output is in array how can i make the Output in xml what i must Change in check sample code ? thanks 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 5, 2015 Share Posted December 5, 2015 To be honest I am not sure. We have only been using the addon for a little over two weeks. But it shouldn't be a problem to parse PHP over to XML http://www.w3schools.com/php/php_xml_simplexml_read.asp 0 Quote Link to comment Share on other sites More sharing options...
Lui2004 Posted December 6, 2015 Author Share Posted December 6, 2015 How can i make this output Array ( [status] => invalid [Massage] => domain invalid [Remotecheck] => 1 ) License key is invalid in a xml output because because the other php cant Read array only xml output. Thanks for help 0 Quote Link to comment Share on other sites More sharing options...
Sliffer21 Posted December 6, 2015 Share Posted December 6, 2015 To be honest I am not sure right off, it shouldn't be hard I just haven't personally worked with XML much 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted December 6, 2015 Share Posted December 6, 2015 How can i make this output Array ( [status] => invalid [Massage] => domain invalid [Remotecheck] => 1 ) License key is invalid in a xml output because because the other php cant Read array only xml output. Thanks for help you need to apply little change in your check license function, first the function expect to get two arguments like this: function yourprefix123_check_license($licensekey, $localkey='') { add a third argument called ($output) so it should look like: function yourprefix123_check_license($licensekey, $localkey='', $output='') { now you need to place the following code between the last two lines of this function, copy this: # output options if (strtolower($output)==="xml"){ $output = ''; $output .= '<licensedata>'; $output .= '<remotecheck>'.$results['remotecheck'].'</remotecheck>'; $output .= '<status>'.$results['status'].'</status>'; $output .= '<description>'.$results['description'].'</description>'; $output .= '<localkey>'.$results['localkey'].'</localkey>'; $output .= '</licensedata>'; } else { $output = $results; } place it here unset($postfields,$data,$matches,$whmcsurl,$licensing_secret_key,$checkdate,$usersip,$localkeydays,$allowcheckfaildays,$md5hash); <-------- place the new code here return $results; } and change "return $results;" to "return $output;" so the final result of this modification will be similar to below: function yourprefix123_check_license($licensekey, $localkey='', $output='') { // the rest of function code ........... unset($postfields,$data,$matches,$whmcsurl,$licensing_secret_key,$checkdate,$usersip,$localkeydays,$allowcheckfaildays,$md5hash); # output options if (strtolower($output)==="xml"){ $output = ''; $output .= '<licensedata>'; $output .= '<remotecheck>'.$results['remotecheck'].'</remotecheck>'; $output .= '<status>'.$results['status'].'</status>'; $output .= '<description>'.$results['description'].'</description>'; $output .= '<localkey>'.$results['localkey'].'</localkey>'; $output .= '</licensedata>'; } else { $output = $results; } return $output; } now when you call this function you have two type of out put Array and XML, to get the XML add the last (third) argument to "xml" $licensedata = yourprefix123_check_license($licensekeyfromdb, $localkeyfromdb, "xml"); this will return the license check results in XML format, or you can leave it empty and it will return the array instead. 0 Quote Link to comment Share on other sites More sharing options...
piticu81 Posted December 1, 2022 Share Posted December 1, 2022 hello im get this error on php 8.1 ArgumentCountError: mktime() expects at most 6 arguments, 7 given in /var/www/vhosts/ on php 7.4.is work anyone know whay im get this error? 0 Quote Link to comment Share on other sites More sharing options...
mfoland Posted September 11, 2023 Share Posted September 11, 2023 @piticu81 I'm just looking at this threat as I'm having to re-familiarize myself with the Licensing Addon. I got out of developing for a while, and I'm back into it. If you haven't figured out the error about mktime in php 8, here you go: https://www.php.net/manual/en/function.mktime.php 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.