[PHP] Inserire una licenza nel tuo software web!
Posted on 26. Nov, 2009 by daniele in php, sicurezza, tutorials
Capita spesso di vendere un vostro software web ma il problema si presenta se l'acquirende utilizza il vostro software in tanti siti o addirittura lo distribuisce in rete! Come si puņ risolvere questo grandissimo problema? Seguite il tutorial!
Per prima cosa creiamo una tabella sul nostro database:
CREATE TABLE `licenses` ( `id` int(50) NOT NULL AUTO_INCREMENT, `domain` varchar(200) NOT NULL, `ip` varchar(50) NOT NULL, `status` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM;
Adesso creiamo la pagina server.php, anche questo file va caricato sul nostro server:
< ?php /** * To begin with we need to setup the configuration so we are able to connect to the database. */ $conn = mysql_connect("DB_HOST","DB_USER","DB_PASS"); // Replace DB_HOST with localtion of database usually localhost and DB_USER and DB_PASS with your database details if (!$conn) die ("Could not connect MySQL"); // Check if could connect to mysql db. mysql_select_db("DB_NAME",$conn) or die ("Could not open database"); // Replace DB_NAME with database name and open the database. If not die <img src='http://www.sastgroup.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . /** * First we will retrieve the variables from the POST sent to us. * And we will make sure they are safe to be used. */ foreach ($_POST as $key => $value) // Go through all items in the $_POST array { // Carry out the foreach on the $field assigning the key and value of the array to $key and $value. $key = strip_tags($key); // Remove any tags from the key $value = strip_tags($value); // Remove any tags from the value $_POST[$key] = htmlentities($value, ENT_QUOTES); // Convert all applicable characters to HTML entities and assign them back to $_POST array. } /** * Now we need to check if the information passed to use is genuine */ $retrieve_q = mysql_query("SELECT * FROM `licenses` WHERE `domain` = '".$_POST['domain']."' && `ip` = '".$_POST['ip']."' && `status` = 'active'"); // Select from the licenses table where the domain, ip match the details passed from the local server and check if the license status is active. if(mysql_num_rows($retrieve_q)){ // Check if any rows match the criteria above. echo "valid"; // If they do echo valid. }else{ echo "invalid"; // If not echo invalid. } ?>
Infine creiamo il file local.php, questo file va caricato sul client del cliente:
< ?php /** * First we must retrieve the domain name and the server ip. */ $domain = str_ireplace("www.", "", $_SERVER['HTTP_HOST']); // Remove www. if it has it $ip = $_SERVER['SERVER_ADDR']; // Get server ip /** * Now we will create the function which will connect to the license server and retrieve the status. */ function license_check($url, $curl_data) // Start license_check function { $options = array(CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_USERAGENT => $domain . "(" . $ip . ") LICENSE CHECK", // who am i CURLOPT_CONNECTTIMEOUT => 60, // timeout on connect CURLOPT_TIMEOUT => 60, // timeout on response CURLOPT_POST => 1, // i am sending post data CURLOPT_POSTFIELDS => $curl_data, // Post data ); $ch = curl_init($url); // Start the connection to $url curl_setopt_array($ch, $options); // Set the options above into the curl $content = curl_exec($ch); // Execute the connection with the options and retrieve the page curl_close($ch); // Close Connecion return $content; // Return $content } /** * Now to use the function we just created and check the license if valid. */ $license = license_check("URL TO SERVER.PHP", "domain=" . $domain . "&ip=" . $ip); // Run the function connecting to the location of the server.php and with the domain and ip post variables if ($license == "valid") // Check if $license returned valid or not. { echo "You have a VALID License. <img src='http://www.sastgroup.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> "; // If it did echo valid }else{ die("Unable to find a valid license for this domain and server ip."); // If not show stop anything else running and show error message. } ?>
TRUCCO:
Vi consiglio di nascondere per benino il file local.php o addirittura criptate la pagina in modo da evitare di rimuovere il file.
Un ottimo tool online per ciptare le pagine č freephpencoder.com oppure per una cosa professionale scaricate il programma a pagamento Ioncube!







Leave a reply