function downloadContentMemory($url, &$content, $strip_crlf = false, $split_crlf = false, $data = array(), $cache = true, $debug = false, &$from_cache) { global $lpsf; if (!function_exists(curl_exec)) { throw new Exception("curl support is not installed", 1); } if ($cache) { $cache_content = ""; $cache_path = "./cache/"; $cache_prefix = "curl"; $cache_hash = hash("sha256", $url . serialize($data) . $strip_crlf . $split_crlf); $cache_hash = str_pad(dec2string(string2dec($cache_hash, 16), 62), 43, '0', STR_PAD_LEFT); if (($from_cache = isCacheReady($cache_path, $cache_prefix, $cache_hash, 86400 * 365, $content)) === TRUE) { return true; } } $host = parseUrl($url); $ua = get_user_agent($host['host']); $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "gzip,deflate", CURLOPT_USERAGENT => $ua, CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_VERBOSE => $debug ? 1 : 0); if (isset($data['httpheader'])) { $options[CURLOPT_HTTPHEADER] = $data['httpheader']; } if (isset($data['poststring'])) { $options[CURLOPT_POST] = substr_count($data['poststring'], "&") + 1; // i am sending post data $options[CURLOPT_POSTFIELDS] = $data['poststring']; // this are my post vars } if (getenv('http_proxy') != "") { $options[CURLOPT_PROXY] = getenv('http_proxy'); // $options[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5; } $ch = curl_init($url); curl_setopt_array($ch, $options); $content = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch); $header = curl_getinfo($ch); curl_close($ch); //$header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; //$content = iconv($encoding, "UTF-8//TRANSLIT", $content); //$content = ForceUTF8\Encoding::toUTF8($content); if (0 == strlen($content)) { return false; } if ($split_crlf) { // result becomes array $content = preg_split("/[\r\n|\n\r|\n]/", $content, NULL, PREG_SPLIT_NO_EMPTY); } if ($strip_crlf) { $content = str_replace(array("\r\n", "\n\r", "\n"), array("", "", ""), $content); } if (!is_array($content)) { $content = array($content); } if ($err == 0) { if ($cache) { fillCache($cache_path, $cache_prefix, $cache_hash, $content); } } else { return false; } return true; }
function test_string2dec() { print "====sha1" . PHP_EOL; print hash('sha1', '') . PHP_EOL; print "da39a3ee5e6b4b0d3255bfef95601890afd80709" . PHP_EOL; print string2dec("da39a3ee5e6b4b0d3255bfef95601890afd80709", 16) . PHP_EOL; print dec2string(string2dec("da39a3ee5e6b4b0d3255bfef95601890afd80709", 16), 62) . PHP_EOL; print "====sha224" . PHP_EOL; print hash('sha224', '') . PHP_EOL; print "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f" . PHP_EOL; print string2dec("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", 16) . PHP_EOL; print dec2string(string2dec("d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", 16), 62) . PHP_EOL; print "====256" . PHP_EOL; print hash('sha256', '') . PHP_EOL; print "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" . PHP_EOL; print string2dec("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16) . PHP_EOL; print dec2string(string2dec("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16), 62) . PHP_EOL; print "====384" . PHP_EOL; print hash('sha384', '') . PHP_EOL; print "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b" . PHP_EOL; print string2dec("38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b", 16) . PHP_EOL; print dec2string(string2dec("38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b", 16), 62) . PHP_EOL; print "====512" . PHP_EOL; print hash('sha512', '') . PHP_EOL; print "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" . PHP_EOL; print string2dec("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", 16) . PHP_EOL; print dec2string(string2dec("cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", 16), 62) . PHP_EOL; $i = 0; while (true) { $h = hash('sha256', $i); $cache_hash1 = dec2string(string2dec($h, 16), 62); $cache_hash2 = str_pad(dec2string(string2dec($h, 16), 62), 43, '0', STR_PAD_LEFT); //print ">" . $h . PHP_EOL; //print ">" . string2dec($h, 16) . PHP_EOL; print ">" . $cache_hash1 . PHP_EOL; print "<" . $cache_hash2 . PHP_EOL; //print $i . " => " . dec2string($i,62) . PHP_EOL; print "=================================================================" . PHP_EOL; $i++; } }