Basically i am trying to write a PHP License scrip for my Product
Since i am newbie to PHP I can't do that well
I need a PHP License script where a text file will be hosted in my server when the client uses the product for first time it must validate with the server i.e the keys available in text file and must proceed
Please note that the Single Text file posted in my server will contain a lot of keys one by one belong to different users
So the Script must get power find that Key exactly and verify that

Thank you :)

Recommended Answers

All 7 Replies

Please Post any updates :)

I'd suggest using a database (MySQL in the below example) that has keys in it. The keys will be generated by a script, that you will execute one time. Sha1() is a encryption function, that returns a combination of numbers and letters, howmanny times you want to encrypt the key is up to you, but I suggest you dont use the amount used in the example.

The table:

CREATE TABLE keys (
key_id INT(11) NOT NULL AUTO_INCREMENT,
key CHAR(255) NOT NULL,
activation CHAR(3) DEFAULT "no",
PRIMARY KEY (key_id) )

And a script that makes the keys:

//
// The database connection etc. here
//

$key_amount = 600;
for ($i = 0; $i < $key_amount; $i++) {
     $key = sha1(sha1($i));
     $query = "INSERT INTO keys (key) VALUES ('".$key."')";
     $result = mysql_query($query) or die ("Could not make key");
}

And a script that validates and activates the key it got from the url (validate.php?key=0029jmvojsf83208502jf)

//
// The database connection comes here....
//

$key = addslashes(htmlentities($_GET['key']));
if ($key == "") {
die("No key found");
}
$query = "SELECT * FROM keys WHERE key='".$key."'";
$result = mysql_query($query) or die("Could not execute query");
if (mysql_num_rows($result) > 0) {
echo "Key valid";

// Setting the key activated

$query = "UPDATE keys SET activation='yes' WHERE key='".$key."'";
$result = mysql_query($query);
} else {
echo "Key invalid";
}

~G

I'd suggest using a database (MySQL in the below example) that has keys in it. The keys will be generated by a script, that you will execute one time. Sha1() is a encryption function, that returns a combination of numbers and letters, howmanny times you want to encrypt the key is up to you, but I suggest you dont use the amount used in the example.

The table:

CREATE TABLE keys (
key_id INT(11) NOT NULL AUTO_INCREMENT,
key CHAR(255) NOT NULL,
activation CHAR(3) DEFAULT "no",
PRIMARY KEY (key_id) )

And a script that makes the keys:

//
// The database connection etc. here
//

$key_amount = 600;
for ($i = 0; $i < $key_amount; $i++) {
     $key = sha1(sha1($i));
     $query = "INSERT INTO keys (key) VALUES ('".$key."')";
     $result = mysql_query($query) or die ("Could not make key");
}

And a script that validates and activates the key it got from the url (validate.php?key=0029jmvojsf83208502jf)

//
// The database connection comes here....
//

$key = addslashes(htmlentities($_GET['key']));
if ($key == "") {
die("No key found");
}
$query = "SELECT * FROM keys WHERE key='".$key."'";
$result = mysql_query($query) or die("Could not execute query");
if (mysql_num_rows($result) > 0) {
echo "Key valid";

// Setting the key activated

$query = "UPDATE keys SET activation='yes' WHERE key='".$key."'";
$result = mysql_query($query);
} else {
echo "Key invalid";
}

~G

Please note that it involves number of Licenses stored in a DB and alos it should regularly check the license validity atleast 2 days one

Thank you for your help Graphix!

Hey mate, for some reason when I try to create the table with the sql code it gives me an error in PHPMYADMIN.

When I make it manually it works, but now, when I try to create a key it wont work, it just Could not make key...

Any reason why?

Member Avatar for diafol

JB - you're asking for help with this, but have not posted any of your own code. You should show some effort yourself.

If you just want a ready made script - use Google.
If you want somebody to write a script for you - search for a freelance php programmer and be prepared to pay them.
If however, you want some help with your own code, post it here and we'll be glad to help.

This is a helpful thread but it is quite old and the mysql code is outdated. Any chance of updating the mysql code for mysql 5.5+?

The queries don't need updating. I do suggest to switch to the mysqli or pdo extension.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.