diff options
-rw-r--r-- | url.class | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -251,13 +251,31 @@ function get($p=null, $timeout=5000) foreach ($p['data'] as $key => $value) $data_pairs[] = "$key=".urlencode($value); - $p['data'] = implode('&', $data_pairs); + $data = implode('&', $data_pairs); } - $data = !empty($p['data']) ? "\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: " . strlen($p['data']) . "\r\n\r\n" . $p['data'] : ""; + $p['headers'] = (array)$p['headers'] + array( + 'Host' => $url->realhostname, + 'User-Agent' => "Mozilla/4.0 (compatible; MSIE 6.0; ITools)", + 'Accept-Language' => T_lang(), + ); + + if ($datalen = strlen($data)) + { + $method = "POST"; + $p['headers'] += array( + 'Content-Type' => "application/x-www-form-urlencoded", + 'Content-Length' => $datalen, + ); + } + else + $method = "GET"; + + foreach ($p['headers'] as $header => $value) + $headers .= "$header: $value\r\n"; stream_set_timeout($fp, intval($p['timeout']/1000), ($p['timeout']%1000)*1000); - @fputs($fp, (empty($data)?'GET':'POST') . " /$url->path HTTP/1.0\r\nHost: $url->realhostname\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; ITools)$data\r\n\r\n"); + @fputs($fp, "$method /$url->path HTTP/1.0\r\n$headers\r\n$data"); while (!feof($fp) && ($line = @fgets($fp, 10240)) && ($line = trim($line))) { @@ -300,8 +318,9 @@ function get_cache_filename($p) if (!is_array($p)) $p = array('url'=>$p); $p += array('cachedir' => $GLOBALS['ULTRAHOME'] . "/var/urlcache"); + $filename = md5(T_lang() . $p['url']); - return $p['cachedir'] . "/" . substr(md5($p['url']), 0, 2) . "/" . md5($p['url']); + return $p['cachedir'] . "/" . substr($filename, 0, 2) . "/$filename"; } |