Skip to content

Check license sample

Michel edited this page Dec 30, 2018 · 2 revisions
function check_license(){
    $sml_url    = 'https://domain.com/';
    $slm_action = 'slm_check';
    $secret_key = '89gOJB54bd6553bd5.06777yr5NSbgT4';

    $license_key = get_license_key();
    $api_call    = $sml_url . '?secret_key=' . $secret_key . '&slm_action=' . $slm_action . '&license_key=' . $license_key;

    define('URL_SERVICE', $api_call);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, URL_SERVICE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $json = curl_exec($ch);
    curl_close($ch);
    $response = json_decode($json, true);

    $result              = $response["result"];
    $message             = $response["message"];
    $status              = $response["status"];
    $registered_devices  = ((is_array($response["registered_devices"]) ? count($response["registered_devices"]) : 0));
    $email               = $response["email"];
    $max_allowed_devices = $response["max_allowed_devices"];
    $date_created        = $response["date_created"];
    $date_renewed        = $response["date_renewed"];
    $date_expiry         = $response["date_expiry"];
    $usr_email           = preg_replace('/%40/', '@', $email);
    $expire              = strtotime($date_expiry);
    $today               = strtotime("today midnight");

    //var_dump($response );

    if($result == 'success' && $status == 'pending'){
        if($today >= $expire){
            return 'Error';
        }
        else {
            return 'Success';
        }
    }
    else {
        if ($result !== 'success') {
            return 'Error';
        }
        else {
            if ($registered_devices < $max_allowed_devices && $status == 'act'.'ive') {
                if($today >= $expire){
                    return 'Error';
                }
                else {
                    return 'Success';
                }
            }
            elseif ($registered_devices > $max_allowed_devices) {
                return 'Error';
            }
            else {
                return 'Error';
            }
        }
    }
}
Clone this wiki locally