Exemple #1
0
function urlfetch($uri, $postdata = null, $headers = null, $timeout = 15)
{
    global $proxy_name, $proxy_ip, $proxy_port, $cacheTime;
    $cacheIt = false;
    if (empty($postdata)) {
        $method = 'GET';
        $cacheIt = hitCache($uri, $cacheTime);
    } else {
        $method = 'POST';
        $data = '';
        foreach ($postdata as $key => $val) {
            if ($data != '') {
                $data .= '&';
            }
            $data .= "{$key}={$val}";
        }
    }
    logf($method . ': ' . $uri);
    $ssl = '';
    if ($proxy_port == 443) {
        $ssl = 'ssl://';
    }
    $fp = fsockopen($ssl . $proxy_ip, $proxy_port, $errno, $errstr, 5);
    if (!$fp) {
        return false;
    }
    stream_set_timeout($fp, $timeout);
    $response = '';
    $out = "{$method} {$uri} HTTP/1.0\r\n";
    $out .= "Host: {$proxy_name}\r\n";
    if (is_array($headers)) {
        foreach ($headers as $key => $val) {
            $out .= "{$key}: {$val}\r\n";
        }
    }
    $out .= "User-Agent: TwiyiaProxy/1.0\r\n";
    $out .= "Content-type: application/x-www-form-urlencoded\r\n";
    $out .= "Content-length: " . strlen($data) . "\r\n";
    $out .= "Connection: Close\r\n\r\n";
    $out .= $data;
    fwrite($fp, $out);
    while (!feof($fp)) {
        $response .= fgets($fp, 128);
    }
    fclose($fp);
    if (empty($response)) {
        return false;
    }
    $responses = explode("\r\n\r\n", $response, 2);
    $headers = explode("\r\n", $responses[0]);
    if (count($headers) < 2) {
        return false;
    }
    $body = $responses[1];
    if ($cacheIt & strpos($headers[0], '200') > 0) {
        doCache($uri, $body);
    }
    return array('headers' => $headers, 'body' => $body);
}
Exemple #2
0
 private function error($error, $query = false)
 {
     $this->DBstats['error']++;
     if ($query != false) {
         $error .= " -->|" . $query . "|<--";
     }
     switch ($this->DBerror) {
         case 'DIE':
             die($error);
             break;
         case 'PRINT':
             echo "<br><b>" . $error . "</b><br>";
             break;
         case 'ALERT':
             echo "<script language='javascript'>\n<!--\nalert(\"database error:\\n" . mysql_real_escape_string($error) . "\");\n// -->\n</script>";
             break;
         case 'LOG':
             logf("MySQL ERROR: " . $error);
             break;
         default:
             flush();
             break;
     }
 }
<?php

// logging function that accepts printf-style formatting
// it prints a time stamp, the string, and a new line
function logf()
{
    $date = date(DATE_RSS);
    $args = func_get_args();
    return print "{$date}: " . call_user_func_array('sprintf', $args) . "\n";
}
logf('<a href="%s">%s</a>', 'http://developer.ebay.com', 'eBay Developer Program');