Basically i am trying to write a PHP License script 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
This is an unefficient and insecure method, but here is example code according to your request/question: <?php /* Very basic example..place this code within the product which your client has. */ //connect to the license file - located on your site... - to verify license. $file = file_get_contents('http://remotelicenseserver.com/keys.txt'); //the key which it attempts to find within the text file... $license_key = 'abdefg'; if(!stristr($file, $license_key)){ //kill execution with an message if the key is invalid... exit('Invalid license key!'); } ?> PHP: If you do decide to use this, I suggest you encode the code.
Following on from what danx10 wrote re: security If you want to make it secure, you would be better off building it as a web service. Having a file of all of your keys is just asking for them to be stolen renedering it useless.
I tried that but it showed me Fatal error: Call to undefined function file_get_content() in /home/USER/DOMAN.COM/i.php on line 7 May i know you have any fix for that! Thanks for helping me asap! Meanwhile i will encode that with ioncube mostly! Thanks
@ roopajyothi Woops, *needs to learn to not rush code especially when attempting to multi-task* updated code
Hi, Again thanks for your help but i get an Blank page when i run this code May i know how to fix that??
Its probably because the product is licensed, it would only display something if the license was'nt within the file.
$license_key = $_GET['lic']; --> usage: GET license.php?lic=yourlicensekey $license_key = $_POST['lic']; usage: POST license.php | FORM { lic: yourlicensekey } The code above is very basic php code, you should try to read Teach yourself php in 24 hours, which help you learn fully PHP in 24 hours straight, no sleep..
Place the following within keys.txt (http://remotelicenseserver.com/keys.txt): abdefg Code (markup): Place the following code within a product: <?php /* Very basic example..place this code within the product which your client has. */ error_reporting(E_ALL); //connect to the license file - located on your site... - to verify license. $file = file_get_contents('http://remotelicenseserver.com/keys.txt'); //the key which it attempts to find within the text file... $license_key = 'abdefg'; if(!stristr($file, $license_key)){ //kill execution with an message if the key is invalid... exit('Invalid license key!'); } else { echo "Product is licensed"; } ?> PHP:
Once the code is out of your hands, it can be cracked. As said before, this is a really insecure method and will be defeated easily... I suggest you invest in either hosting the script yourself and collecting monthly fees from users or using ioncube or zendguard.
It doesn't care about numbers in lic.txt file When i put the word welcome48474 in lic.txt and the $license_key = 'welcome'; Its shows that the product is Licensed Any Fix please???
Place each key within a new line. <?php error_reporting(E_ALL); //connect to the license file - located on your site... - to verify license. $file = file('http://remotelicenseserver.com/keys.txt'); $file = array_map('trim', $file); //the key which it attempts to find within the text file... $license_key = 'abdefg'; if (!in_array($license_key, $file)){ //kill execution with an message if the key is invalid... exit('Invalid license key!'); } else { echo "Product is licensed"; } ?> PHP: