PDA

View Full Version : Simple License System



Luno1599
02-10-2009, 08:28 AM
Hey,

I am designing a script and I want the users to need a license to run the script. Its a free script but I just want a quck and easy way for me to track usage.

I have made a script but I cant get the dam thing to work.

Here is thats is built into the script

$check_license = get_file_contant(http://URL/license.php?license=check&url=http://www.roizer.com&license=ipvdD563YjhPeS8);

Here is whats in the license file on my server:


if($_GET['license'] == "check"){

$url = $_GET['url'];
$license = $_GET['license'];

/* Setup MySQL Access */
$DBhost = "localhost";
$DBuser = "";
$DBpass = "";
$DBname = "";
mysql_connect($DBhost, $DBuser, $DBpass) or die ("Cannot connect to database server");
mysql_select_db($DBname) or die ("Cannot select site database");

$date = date("d-m-Y");

$license_query = mysql_query("SELECT * FROM `license` WHERE `key` = '$key'");
$license_row = mysql_fetch_array($license_query);
$dbexpires = $license_row['expires'];
$dburl = $license_row['url'];
$dbkey = $license_row['key'];
echo "$dbkey" . "<br>" . "$dburl" . "<br>" . "$dbexpires";


if($dbkey != $license){
echo "Error No License";
return "3";
}else

if($dburl != $url){
echo "URL Wrong!";
return "4";
}else

if($date >= $dbexpires){
echo "EXPIRED";
return "5";
}else

return "6";
}



(this is just a test script but I cant get it to work, if the domain is wrong it echos wrong license and if the license if wrong it still echos wrong license and if the license in the db expirery date is less then the date today it still says no license and will not work for anything!! Help!

Dan

Blinger1
02-10-2009, 09:06 AM
Change the first license to another variable, because the second one (where the key is ipvdD563YjhPeS8) over rights the first variable (check) :)

Make a basic check first, like this (possibly not the best coding ever!):



<?php

$url = $_GET['url'];
$license = $_GET['license'];

echo("license: $license");
echo("<br>");
echo("url: $url");

?>


edit: with the above code, go to the website like this "www.mysite.com/index.php?license=check&url=http://www.roizer.com" look at the output, it should be
license: check
url: http://www.roizer.com and if you go to www.mysite.com/index.php?license=check&url=http://www.roizer.com&license=ipvdD563YjhPeS8 , the output should be
license: ipvdD563YjhPeS8
url: http://www.roizer.com


make any sense?

Luno1599
02-10-2009, 10:41 AM
Yeahh thanks, saw that bug just after I posted! But yeah fixed now, thanks!!

Dan

Source
02-10-2009, 11:52 AM
Probably the best way todo it so you can handle error's script side is to have a license php script to return a JSON output. A lot easier than processing a html page as such.

Sorry for such a crude example

licenseCheck.php



<?php

$licenseID = $_GET['id'];
$licenseURL = $_GET['url'];

// blah - processing code here

$jsonArray['status'] = 'valid';
$jsonArray['url'] = 'url it is licensed to';
$jsonArray['name'] = 'license holder';

echo json_encode( $jsonArray );

?>


and the code to get the license info for script-side checking/processing



<?php

$licenseCheck = file_get_contents( 'http://url/licenseCheck.php?id=123143241&url=http://www.mysite.com' );
$licenseInfo = json_decode( $licenseCheck );

// this will echo "valid" in the current preview
echo $licenseInfo->status;

// this will echo "url it is licensed to"
echo $licenseInfo->url;

// etc

?>


If it were a paid script you would have to try and take measures to stop people from nulling it, but because it's a free script you don't really have todo anything. Albeit the idea a bit pointless.

Luno1599
02-10-2009, 02:31 PM
I tryed adding something like this into my script so it echos in the main script when it expires ect but I cant get it to work :(

Dan

LMS16
02-10-2009, 05:08 PM
make it get the contents from that file, but on instalation make them input their details so that it inputs into their db. If it has expired or doesnt exist then it can execute something on their side.

Lew.

Blob
02-10-2009, 08:56 PM
make it get the contents from that file, but on instalation make them input their details so that it inputs into their db. If it has expired or doesnt exist then it can execute something on their side.

Lew.

If it is entering into their database, people can easily change it.

LMS16
03-10-2009, 09:12 AM
No, i meant enter their license into their db...

Lew.

Luno1599
03-10-2009, 11:36 AM
No, i meant enter their license into their db...

Lew.

Thats is what they do, but I want to send information back from the callback script.

LMS16
03-10-2009, 01:00 PM
yes, make the script on your server return true or false, then on their side make the script decide what to do if true or false is called bk.

Want to hide these adverts? Register an account for free!