please help with the code...

Discussion in 'PHP' started by nQQb, May 31, 2009.

  1. #1
    Hi, I have been trying to fix an issue on this code but no luck. This code checks for key if it exists for a license, if found on local, it ignores the remote callback. But seems like it is checking for license on remote and ignoring local key (well not ignoring, but regenerating local key each time with new hit). Could you please advise by looking at the code? :confused:

    $remote_auth = str_replace(".","",$_SERVER[SERVER_NAME]);
                    
                 $key = file_exists(dirname(__FILE__)."/key.php")?file_get_contents(dirname(__FILE__)."/key.php"):false;
    
                    if ($key !== false)
                    {
                            $key = str_replace("\n", '', $key); // Remove the line breaks from the key string
    
                            // Split out SHA1 hash from the key data
                            $key_string = substr($key, 0, strlen($key)-40);
                            $key_sha_hash = substr($key, strlen($key)-40, (strlen($key)));
                            
                            if (sha1($key_string.$remote_auth) == $key_sha_hash) // Compare SHA1 hash to the key data
                            {         
                                    $key = strrev($key_string); // Back the right way around
    
                                    $key_hash = substr($key, 0, 32); // Get the MD5 hash of the data from the string
                                    $key_data = substr($key, 32); // Get the data from the string
    
                                    $key_data = base64_decode($key_data);
                                    $key_data = unserialize($key_data);
                                                               
                             
                                           if ((time()>$key_data['expiry']))
                                            {
                                                    @unlink(dirname(__FILE__)."/key.php");
                                                    $remote = true;
                                                    $valid = false;
                                            }
                                            else
                                            {
                                                                                                    $remote = true;
                                                    $remote = false;
                                                    $valid = true;
    
                                            }
                            }
                            else
                            {
                                                    @unlink(dirname(__FILE__)."/key.php");
                                                    $remote = true;
                                                    $valid = false;
                            }
                    }
                    else
                    {
                                                    @unlink(dirname(__FILE__)."/key.php");
                                                    $remote = true;
                                                    $valid = false;
                    }
    PHP:
     
    nQQb, May 31, 2009 IP
  2. jsamdirect

    jsamdirect Peon

    Messages:
    61
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Shouldn't this be if($key != false)? I think the !== is the issue.
     
    jsamdirect, Jun 3, 2009 IP