1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Error with php licensing script

Discussion in 'PHP' started by CHWH-Admin, Aug 5, 2012.

  1. #1
    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
     
    CHWH-Admin, Aug 5, 2012 IP
  2. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Well whats wrong with it? Any errors?
     
    PK-Host, Aug 6, 2012 IP
  3. CHWH-Admin

    CHWH-Admin Active Member

    Messages:
    342
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    #3
    Only Getting "<"
     
    CHWH-Admin, Aug 6, 2012 IP
  4. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Really gonna have to narrow that down. What happens if you visit the server side and what happens if you visit the client side?
     
    PK-Host, Aug 6, 2012 IP
  5. CHWH-Admin

    CHWH-Admin Active Member

    Messages:
    342
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    #5
    Client Side : i'm getting "<"

    Server Side: blank screen
     
    CHWH-Admin, Aug 6, 2012 IP
  6. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #6
    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:
     
    PK-Host, Aug 6, 2012 IP
  7. CHWH-Admin

    CHWH-Admin Active Member

    Messages:
    342
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    #7
    Thanks pk-host.
    i try this updated script... but always getting "Invalid Details."
     
    CHWH-Admin, Aug 6, 2012 IP
  8. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #8
    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.
     
    PK-Host, Aug 6, 2012 IP
  9. CHWH-Admin

    CHWH-Admin Active Member

    Messages:
    342
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    #9
    Result is

    "Array ( [key] => 123-456 [domain] => xxxxx.com [website_ip] => 111.5.xxx.456 ) Invalid Details."
     
    CHWH-Admin, Aug 6, 2012 IP
  10. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #10
    and are they the details that are inside of the sql database? as they are there?
     
    PK-Host, Aug 6, 2012 IP
  11. CHWH-Admin

    CHWH-Admin Active Member

    Messages:
    342
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    #11
    Yes the same details is in the sql files
     
    CHWH-Admin, Aug 6, 2012 IP
  12. PK-Host

    PK-Host Guest

    Messages:
    109
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #12
    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?
     
    PK-Host, Aug 6, 2012 IP
  13. CHWH-Admin

    CHWH-Admin Active Member

    Messages:
    342
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    #13
    Result is

    Array ( [key] => 123-456 [domain] => xxxxxxxx.com [website_ip] => 111.5.xxx.456 ) 1
     
    CHWH-Admin, Aug 6, 2012 IP
  14. CHWH-Admin

    CHWH-Admin Active Member

    Messages:
    342
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    85
    #14
    any idea about this error ?
     
    CHWH-Admin, Aug 6, 2012 IP