0

This is my first time posting here! :) I have made a php license generation and validation system. The server end communicates with the mysql database and outputs a json result like the following:

{"valid":"true","info":{"id":"1","expire":"1421811123"}}

The problem is on the client server where i have the following script:

<?php


$key_info['key'] = "KEY"];
$serverurl = "http://URLTOSERVER";

$ch = curl_init ($serverurl);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt ($ch, CURLOPT_POST, true);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $key_info);

$result = curl_exec ($ch);
$result = json_decode($result, true);

if($result['valid'] == true){

        echo "valid";
}
else {
        die("Invalid Key!");

}


?>

When i run this i get "valid" every time, even when i enter the wrong key - i have tried printing the output and i can confirm that.

Please advise.

Thanks.

1 Answer 1

2

Your JSON contains a string true, not a boolean true. Any string in there will pass == true.

if($result['valid'] == 'true'){
Sign up to request clarification or add additional context in comments.

2 Comments

Can't believe the amount of time i spent checking what was wrong! Thanks, solved! :)
@aqq License keys and encrypted code with PHP is a losing battle, in my opinion. You need something like ioncube.com but they're expensive, limit compatibility, and are still breakable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.