• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » PHP » My Way Create License Key For PHP Application

My Way Create License Key For PHP Application

By Sigit Prasetya Nugroho ∙ October 28, 2016 ∙ PHP ∙ 11 Comments

Share : TwitterFacebookTelegramWhatsapp

Seegatesite – Creating PHP license key for secure applications from software piracy. What do you feel if your paid application is used by people who do not have the right to use the application? of course, you are very disappointed and angry. I have experienced this some time ago. My POS Applications that I created in a few months, has been spread by people who do not have a right of usage because the application is not protected. So, an idea occurred to create software license in the form of a license key whenever the user doing the new installation a PHP application on the server locally or online. Here’s a simple way I protect the PHP application with a license key.

Table of Contents

    • 0.1 Basic concepts
    • 0.2 Parameter
    • 0.3 How to check hard drive ID using PHP
  • 1 Tutorial creates a simple license key on PHP application

Basic concepts

My Way Create Simple Php Application License Key

The simple idea is in the header of the script will check if the license key is existing or not? if existing, whether the license key is valid or not. If invalid , the system will redirect users to the activation page to register first.

This activation code is checking the hard drive ID, so 1 license key is valid only for 1 hard drive. This method is effective for the offline application (intranet).

Parameter

To create a license key code, I use some parameters as follows

  • Secret code : a key which is only owned by us as a developer.
  • Username : username of the person who has the right to use the application.
  • Password : the owner password who has the right to use the application.
  • Unique code : In this tutorial, used the hard drive ID as the unique code.

How to check hard drive ID using PHP

To detect the hard drive id in PHP there are 2 ways I do. That is to detect the hard drive id for the windows operating system and detect hard drive id Linux operating systems from PHP server.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
if(strtoupper(PHP_OS) == strtoupper("LINUX"))
{
$ds=shell_exec('udevadm info --query=all --name=/dev/sda | grep ID_SERIAL_SHORT');
$serialx = explode("=", $ds);
$serial = $serialx[1];
}
else
{
function GetVolumeLabel($drive) {
if (preg_match('#Volume Serial Number is (.*)\n#i', shell_exec('dir '.$drive.':'), $m)) {
$volname = ' ('.$m[1].')'; } else { $volname = ''; }
return $volname;
}
$serial = str_replace("(","",str_replace(")","",GetVolumeLabel("c")));
}

Tutorial creates a simple license key on PHP application

Work Flow Tutorial Create License Key Php By Seegatesite

There are 2 sides in making the license key, i.e. from the client side (web application) and the server side (web activator).

Client Side (app folder)

1. Make a folder with name “app“.

2. Create a PHP file with name index.php and copy the following code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<title>Index Page</title>
</head>
<body>
<?php
$secret_code = 'secret';
if(strtoupper(PHP_OS) == strtoupper("LINUX"))
{
$ds=shell_exec('udevadm info --query=all --name=/dev/sda | grep ID_SERIAL_SHORT');
$serialx = explode("=", $ds);
$serial = $serialx[1];
$licensi = md5('username'.'password'.trim($serial).$secret_code);
}
else
{
function GetVolumeLabel($drive)
{
if (preg_match('#Volume Serial Number is (.*)\n#i', shell_exec('dir '.$drive.':'), $m))
{
$volname = ' ('.$m[1].')';
}
else
{
$volname = '';
}
return $volname;
}
$serial = str_replace("(","",str_replace(")","",GetVolumeLabel("c")));
$licensi = md5('username'.'password'.trim($serial).$secret_code);
}
$lisfile = $licensi.'.key';
 
if(!file_exists(__DIR__.'/'.$lisfile))
{
header('Location: activator.html');
}
?>
 
<h1>Welcome to web application</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</html>

Explanation :

When the user open index.php page , the system will check if there is a license key file or not ? If no, then the user will be directed towards the activator page.

3. Create an HTML page with name activator.html and copy the following code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<title>Activator</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12"><h2>Please activate your application before use</h2>
</div>
 
<div class="tab-pane fade active in" role="tabpanel" id="home" aria-labelledby="home-tab">
<h3>* Please be sure you re connected to the Internet</h3>
<div>
<div class="form-group">
<label for="exampleInputEmail1">Username</label>
<input type="text" class="form-control" autofocus id="txtuser" placeholder="Username">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="txtpass" placeholder="Password">
</div>
<div class="form-group">
<label for="exampleInputFile">Web Activator</label>
<input type="text" value="" placeholder="URL WEB SERVER" class="form-control" id="txtweb">
</div>
<button type="submit" id="btnonline" class="btn btn-default">Submit</button>
</div>
</div>
 
<div class="col-xs-12" id="result"></div>
 
</div>
 
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 
<script type="text/javascript">
$(document).on("click","#btnonline",function(){
var nama = $("#txtuser").val();
var pass = $("#txtpass").val();
var url = $("#txtweb").val();
var value = {
nama:nama,
password:pass,
url:url,
method : "online",
};
$.ajax(
{
url : "c_activator.php",
type: "POST",
data : value,
success: function(data, textStatus, jqXHR)
{
var data = jQuery.parseJSON(data);
if(data.value == true)
{
$("#result").html("<h2>Application active!!, Thank you</h2><p>You can login from <a href='index.php'>this link</a>");
$("#xtabbs").html("");
}else
{
$("#result").html("Sorry, failed to activate your application");
}
 
},
error: function(jqXHR, textStatus, errorThrown)
{
$("#result").html("error");
}
});
})
</script>
</body>
</html>

4. Create a PHP file with the name c_activator.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) )
{
$method=$_POST['method'];
if($method == 'online')
{
$nama=$_POST['nama'];
$password=$_POST['password'];
if(strtoupper(PHP_OS) == strtoupper("LINUX"))
{
$ds=shell_exec('udevadm info --query=all --name=/dev/sda | grep ID_SERIAL_SHORT');
$serialx = explode("=", $ds);
$serial = $serialx[1];
}
else
{
function GetVolumeLabel($drive) {
if (preg_match('#Volume Serial Number is (.*)\n#i', shell_exec('dir '.$drive.':'), $m)) {
$volname = ' ('.$m[1].')';
} else {
$volname = '';
}
return $volname;
}
$serial = str_replace("(","",str_replace(")","",GetVolumeLabel("c")));
}
$url=$_POST['url'];
$ch = curl_init();  
 
curl_setopt($ch,CURLOPT_URL,$url.'/index.php?nama='.$nama.'&password='.$password.'&serial='.trim($serial));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$output=curl_exec($ch);
 
curl_close($ch);
 
$array= array();
if($output == 'error')
{
$array['value'] = false;
 
}else
{
$content='empty';
$fp = fopen($output.'.key',"wb");
fwrite($fp,$content);
fclose($fp);
$array['value'] = true;
}
echo json_encode($array);
}
 
} else {
exit('No direct access allowed.');
}

Explanation :

The system will send the parameters needed by the server to establish the license key. The system will get the license key code on the server using  curl command.

After the license codes obtained from the server, the system will create a new file with the .key extension -> license_code.key

Build Secure License Key With Php

SERVER SIDE (webkey folder)

1. Create a folder with the name “webkey”

2. Create a file with the name index.php in the webkey folder and copy the following code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$secret_key = 'secret';
$nama = trim($_GET['nama']);
$password = trim($_GET['password']);
$serial = trim($_GET['serial']);
if(!isset($_GET['nama']) OR !isset($_GET['nama']) OR !isset($_GET['serial']) )
{
$licensi = 'error';
}
else
{
if($nama == 'username')
{
       if($password == 'password')
       {
           $as = true;
       }else{
           $as = false;
       }
}
else
{
   $as = false;
}
if($as == true)
{
$licensi = md5($nama.$password.$serial.$secret_key);
}
else
{
$licensi = 'error';
}
}
echo $licensi;
?>

Explanation :

The server will accept the parameters sent by the client, then check each parameter are valid or not. The server will return the license code to the client, and the code will be processed by the client by creating a new file with .key extension.

Up here, you’ve finished making the simple license key using PHP. If you re running the code will be as the following video

Note, if you don’t encrypt your php files, all the above code would be futile anyway. Make sure you perform encryption on your php code using a reliable encryption. For a free encryption, I suggest you use encryption php file from fopo.com.ar (Update : fopo encryption is not available again… i will update this article ASAP :))

Tutorial creates a license key for PHP application is suitable for intranet applications or offline application. If you used online applications such as WordPress themes, plugins, and some tools supporting online applications, how to create the license key? I will discuss on the other occasions.

Please download the full code above at the following link

Download Link : http://wp.me/a65Dpx-BP

Password : seegatesite.com

If there are suggestions and questions please leave a message in the comments below, I will be happy to assist you. So my quick tutorial how to create a license key for a PHP application may help you.

Another PHP Related Post :

  • How To Replace String With Another String In PHP
  • Login Page – Tutorial CRUD Client and API Server Using JQuery And Lumen Part 2
  • Tutorial CRUD Client and API Server Using JQuery And Lumen Part 1
  • How To Solve Problems Illegal mix of collations (latin1_swedish_ci,IMPLICIT) In Laravel
  • How To Resolve No ‘Access-Control-Allow-Origin’ Header In Lumen
  • How To Create Custom Class In Laravel 5.5 For Beginners

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Comments

  1. Avatar for theblacktheblack says

    July 29, 2017 at 9:08 pm

    lmao! i don’t understand these things..but what is the relation between this code and my software??!!!…i want to protect it with a license key or trial makes my software works only for a periode of time….and what’s mean “Updates” …..??? and is it these updates a good idea to protect my software.( my english is sucks hahahhaha don’t lought “…peace.

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      July 30, 2017 at 5:12 am

      My english is not good either … hehehe. You can download a sample project to learn more.

      thank for visit my site

      Reply
  2. Avatar for faezefaeze says

    November 4, 2018 at 11:42 am

    hi, how can I release new license key and remove the previous license key.

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      November 6, 2018 at 8:08 am

      this example cant release new license key and remove the previous license key , sory 🙁

      Reply
  3. Avatar for Danial AfridiDanial Afridi says

    January 7, 2019 at 6:58 pm

    Hello i have question from your article which file i have to make in client file and which file i have to made in my server so i can give him a key to activate my product please reply me there
    redkhan13@gmail.com

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      January 26, 2019 at 3:30 pm

      Please download the source code

      Reply
  4. Avatar for KristenKristen says

    March 2, 2019 at 11:23 am

    Password : seegatesite.com do not working !

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      March 3, 2019 at 7:56 am

      sory the file is corrupted..

      Reply
  5. Avatar for CarlosCarlos says

    July 5, 2020 at 4:14 pm

    Hi, all the time get the same key…. dont detect the hard disk id…. I going to try with the hard disk serial number

    Reply
  6. Avatar for SimoneSimone says

    November 20, 2020 at 1:24 pm

    Hi, I cannot share with share button to unlock the download.
    Thank you in advance

    Reply
    • Avatar for Sigit Prasetya NugrohoSigit Prasetya Nugroho says

      November 20, 2020 at 3:28 pm

      hello simone,

      here is the link

      Download Link : https://seegatesite.com/tutorial-create-license-key-php-source-code/

      Password : seegatesite.com

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for Sigit Prasetya NugrohoThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (7) Publisher Tips (5) react (3) Reactjs (7) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) widget (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2021 Seegatesite.com