Hi, we try to create a small php License System with the help of a php tutorial. but i'm getting some error. Could you please help to troubleshot it ? Client Side File Server Side File SQL File
Really gonna have to narrow that down. What happens if you visit the server side and what happens if you visit the client side?
Client Side (PHP File) <?php $pass_array['key'] = "123-456"; $pass_array['domain'] = $_SERVER['SERVER_NAME']; $pass_array['website_ip'] = $_SERVER['SERVER_ADDR']; function confirm_license($url, $data) { $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => false, CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 50, CURLOPT_TIMEOUT => 50, CURLOPT_MAXREDIRS => 0, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_SSL_VERIFYHOST => 0, ); $ch = curl_init($url); curl_setopt_array($ch, $options); $content = curl_exec($ch); curl_close($ch); return $content; } $license = confirm_license("http://www.yousite.com/path/to/folder/server/", $pass_array); print_r($license); /**if ($license['status'] != "1") { die($license['message']); }*/ ?> PHP: Server Side (PHP File) - All I've done is formatted with correct tabbing. <?php if(!mysql_connect("DATABASE_HOSTNAME", "DATABASE_USERNAME", "DATABASE_PASSWORD")){ echo "Error: Connection To The MySQL Server Failed."; } if(!mysql_select_db("DATABASE_NAME")){ echo "Error: Unable To Select Database."; } $required_keys = array("key", "domain", "website_ip"); foreach ($required_keys as $req_key) { if (array_key_exists($req_key, $_POST)) { $sanitised[$req_key] = stripslashes(strip_tags($_POST[$req_key])); }else{ echo "Error: " . $req_key . " missing from passed variables."; break 1; } } $ret_db = mysql_query("SELECT * FROM `license` WHERE `key` = '" . mysql_real_escape_string($sanitised['key']) . "' && `domain` = '" . mysql_real_escape_string($sanitised['domain']) . "' && `website_ip` = '" . mysql_real_escape_string($sanitised['website_ip']) . "' ORDER BY `id` DESC LIMIT 0,1"); if (mysql_num_rows($ret_db) == "0") { echo "Invalid Details."; }else{ $retdb = mysql_fetch_array($ret_db); if ($retdb['status'] == "active") { echo "1"; }else{ if ($retdb['status'] == "inactive") { echo "Details Valid, License Status Inactive."; }else{ echo "Details Valid, License Status Unknown."; } } } ?> PHP:
On the client side page have it like this <?php $pass_array['key'] = "123-456"; $pass_array['domain'] = $_SERVER['SERVER_NAME']; $pass_array['website_ip'] = $_SERVER['SERVER_ADDR']; function confirm_license($url, $data) { $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => false, CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 50, CURLOPT_TIMEOUT => 50, CURLOPT_MAXREDIRS => 0, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $data, CURLOPT_SSL_VERIFYHOST => 0, ); $ch = curl_init($url); curl_setopt_array($ch, $options); $content = curl_exec($ch); curl_close($ch); return $content; } $license = confirm_license("http://www.yousite.com/path/to/folder/server/", $pass_array); print_r($pass_array); print_r($license); /**if ($license['status'] != "1") { die($license['message']); }*/ ?> PHP: This is still for debugging purposes but will help please post the results here.
Result is "Array ( [key] => 123-456 [domain] => xxxxx.com [website_ip] => 111.5.xxx.456 ) Invalid Details."
Remove the print_r from the clientside and add the print_r as below Server Side <?php if(!mysql_connect("DATABASE_HOSTNAME", "DATABASE_USERNAME", "DATABASE_PASSWORD")){ echo "Error: Connection To The MySQL Server Failed."; } if(!mysql_select_db("DATABASE_NAME")){ echo "Error: Unable To Select Database."; } $required_keys = array("key", "domain", "website_ip"); foreach ($required_keys as $req_key) { if (array_key_exists($req_key, $_POST)) { $sanitised[$req_key] = stripslashes(strip_tags($_POST[$req_key])); }else{ echo "Error: " . $req_key . " missing from passed variables."; break 1; } } [B]print_r($sanitised);[/B] $ret_db = mysql_query("SELECT * FROM `license` WHERE `key` = '" . mysql_real_escape_string($sanitised['key']) . "' && `domain` = '" . mysql_real_escape_string($sanitised['domain']) . "' && `website_ip` = '" . mysql_real_escape_string($sanitised['website_ip']) . "' ORDER BY `id` DESC LIMIT 0,1"); if (mysql_num_rows($ret_db) == "0") { echo "Invalid Details."; }else{ $retdb = mysql_fetch_array($ret_db); if ($retdb['status'] == "active") { echo "1"; }else{ if ($retdb['status'] == "inactive") { echo "Details Valid, License Status Inactive."; }else{ echo "Details Valid, License Status Unknown."; } } } ?> PHP: SELECT * FROM `license` WHERE `key` = '123-456' && `domain` = 'xxxxx.com' && `website_ip` = '111.5.xxx.456' ORDER BY `id` DESC LIMIT 0,1 run that query in PHPMYADMIN does a row come up for that?