Title: Set up php code for activate license
Last modified: July 28, 2022

---

# Set up php code for activate license

 *  Resolved [edmargenesisworkplace](https://wordpress.org/support/users/edmargenesisworkplace/)
 * (@edmargenesisworkplace)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/set-up-php-code-for-activate-license/)
 * Hi please, can you help me with this? I tried to set up the PHP code on my plugin
   and I had already activated the plugin.
 *     ```
       define('YOUR_SPECIAL_SECRET_KEY', 'removed by moderator');
       define('YOUR_LICENSE_SERVER_URL', 'https://www.genesisbusinesssolutions.com'); 
       define('YOUR_ITEM_REFERENCE', 'My First Plugin');
   
       // API query parameters
               $api_params = array(
                   'slm_action' => 'slm_activate',
                   'secret_key' => YOUR_SPECIAL_SECRET_KEY,
                   'license_key' => $license_key,
                   'registered_domain' => $_SERVER['SERVER_NAME'],
                   'item_reference' => urlencode(YOUR_ITEM_REFERENCE),
               );
   
               // Send query to the license manager server
               $response = wp_remote_get(add_query_arg($api_params, YOUR_LICENSE_SERVER_URL), array('timeout' => 20, 'sslverify' => false));
   
               // Check for error in the response
               if (is_wp_error($response)){
                   echo "Unexpected Error! The query returned with an error.";
               }
   
               //var_dump($response);//uncomment it if you want to look at the full response
   
               // License data.
               $license_data = json_decode(wp_remote_retrieve_body($response));
   
               // TODO - Do something with it.
               //var_dump($license_data);//uncomment it to look at the data
   
               if($license_data->result == 'success'){//Success was returned for the license activation
   
                   //Uncomment the followng line to see the message that returned from the license server
                   echo '<br />The following message was returned from the server: '.$license_data->message;
   
                   //Save the license key in the options table
                   update_option('sample_license_key', $license_key); 
               }
               else{
                   //Show error to the user. Probably entered incorrect license key.
   
                   //Uncomment the followng line to see the message that returned from the license server
                   echo '<br />The following message was returned from the server: '.$license_data->message;
               }
       ```
   
 * I think the response has an empty value response. What am I missing in the code?
 * Thank you so much
    -  This topic was modified 3 years, 10 months ago by [edmargenesisworkplace](https://wordpress.org/support/users/edmargenesisworkplace/).
    -  This topic was modified 3 years, 10 months ago by [edmargenesisworkplace](https://wordpress.org/support/users/edmargenesisworkplace/).
    -  This topic was modified 3 years, 10 months ago by [edmargenesisworkplace](https://wordpress.org/support/users/edmargenesisworkplace/).
    -  This topic was modified 3 years, 10 months ago by [edmargenesisworkplace](https://wordpress.org/support/users/edmargenesisworkplace/).
    -  This topic was modified 3 years, 10 months ago by [edmargenesisworkplace](https://wordpress.org/support/users/edmargenesisworkplace/).
    -  This topic was modified 3 years, 10 months ago by [Yui](https://wordpress.org/support/users/fierevere/).
      Reason: formatting
    -  This topic was modified 3 years, 10 months ago by [Yui](https://wordpress.org/support/users/fierevere/).
      Reason: secret key removed

Viewing 1 replies (of 1 total)

 *  Plugin Support [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * (@mbrsolution)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/set-up-php-code-for-activate-license/#post-15869252)
 * Hi, please check the following documentation. This should help you with your 
   issue.
 * [https://www.tipsandtricks-hq.com/software-license-manager-plugin-for-wordpress](https://www.tipsandtricks-hq.com/software-license-manager-plugin-for-wordpress)
 * Kind regards.

Viewing 1 replies (of 1 total)

The topic ‘Set up php code for activate license’ is closed to new replies.

 * ![](https://ps.w.org/software-license-manager/assets/icon-128x128.png?rev=1135848)
 * [Software License Manager](https://wordpress.org/plugins/software-license-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/software-license-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/software-license-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/software-license-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/software-license-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/software-license-manager/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [mbrsolution](https://wordpress.org/support/users/mbrsolution/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/set-up-php-code-for-activate-license/#post-15869252)
 * Status: resolved