private function activate() { /* Any attempt to circumvent activation invalidates your license. We're a small company trying to make something useful at a fair price. Please don't steal from us. */ $Perch = PerchAdmin::fetch(); $host = 'activation.grabaperch.com'; $path = '/activate/'; $url = 'http://' . $host . $path; $data = ''; $data['key'] = PERCH_LICENSE_KEY; $data['host'] = $_SERVER['SERVER_NAME']; $data['version'] = $Perch->version; $data['php'] = phpversion(); $content = http_build_query($data); $result = false; $use_curl = false; if (function_exists('curl_init')) { $use_curl = true; } if ($use_curl) { PerchUtil::debug('Activating via CURL'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); $result = curl_exec($ch); PerchUtil::debug($result); $http_status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_status != 200) { $result = false; PerchUtil::debug('Not HTTP 200: ' . $http_status); } curl_close($ch); } else { if (function_exists('fsockopen')) { PerchUtil::debug('Activating via sockets'); $fp = fsockopen($host, 80, $errno, $errstr, 10); if ($fp) { $out = "POST {$path} HTTP/1.1\r\n"; $out .= "Host: {$host}\r\n"; $out .= "Content-Type: application/x-www-form-urlencoded\r\n"; $out .= "Content-Length: " . strlen($content) . "\r\n"; $out .= "Connection: Close\r\n\r\n"; $out .= $content . "\r\n"; fwrite($fp, $out); stream_set_timeout($fp, 10); while (!feof($fp)) { $result .= fgets($fp, 128); } fclose($fp); } if ($result != '') { $parts = preg_split('/[\\n\\r]{4}/', $result); if (is_array($parts)) { $result = $parts[1]; } } } } // Should have a $result now if ($result) { $json = PerchUtil::json_safe_decode($result); if (is_object($json) && $json->result == 'SUCCESS') { // update latest version setting $Settings = new PerchSettings(); $Settings->set('latest_version', $json->latest_version); $Settings->set('on_sale_version', $json->on_sale_version); PerchUtil::debug($json); PerchUtil::debug('Activation: success'); return true; } else { PerchUtil::debug('Activation: failed'); $this->activation_failed = true; return false; } } // If activation can't complete, assume honesty. That's how I roll. return true; }