Php License Script System

Discussion in 'PHP' started by roopajyothi, Apr 22, 2010.

  1. #1
    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 :)
     
    roopajyothi, Apr 22, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    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.
     
    Last edited: Apr 22, 2010
    danx10, Apr 22, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3
    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.
     
    lukeg32, Apr 22, 2010 IP
  4. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #4
    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, Apr 22, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    @ roopajyothi

    Woops, *needs to learn to not rush code especially when attempting to multi-task* updated code
     
    danx10, Apr 22, 2010 IP
  6. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #6
    Hi,
    Again thanks for your help but i get an Blank page when i run this code
    May i know how to fix that??
     
    roopajyothi, Apr 22, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    Its probably because the product is licensed, it would only display something if the license was'nt within the file.
     
    Last edited: Apr 23, 2010
    danx10, Apr 23, 2010 IP
  8. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #8
    Mate i double checked whatever i put in lic.txt file it display blank only!
     
    roopajyothi, Apr 23, 2010 IP
  9. taduyducvn

    taduyducvn Greenhorn

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #9
    $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..
     
    taduyducvn, Apr 23, 2010 IP
  10. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #10
    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:
     
    danx10, Apr 24, 2010 IP
  11. Brad33

    Brad33 Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    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.
     
    Brad33, Apr 24, 2010 IP
  12. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #12
    Thanks i will encode the script!
    Don't worry :)
     
    roopajyothi, Apr 25, 2010 IP
  13. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #13
    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???
     
    roopajyothi, Apr 25, 2010 IP
  14. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #14
    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:
     
    danx10, Apr 25, 2010 IP
  15. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #15
    Yep!
    I followed that in your last post
    Any will try with this
    Thank you!
     
    roopajyothi, Apr 25, 2010 IP
  16. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #16
    Hope its working any way
    Thanks!
     
    roopajyothi, Apr 25, 2010 IP