コード例 #1
0
ファイル: functions-http.php プロジェクト: chadcumm/YOURLS
/**
 * Default HTTP requests options for YOURLS
 *
 * For a list of all available options, see function request() in /includes/Requests/Requests.php
 *
 * @uses YOURLS_PROXY
 * @uses YOURLS_PROXY_USERNAME
 * @uses YOURLS_PROXY_PASSWORD
 * @since 1.7
 * @return array Options
 */
function yourls_http_default_options()
{
    $options = array('timeout' => yourls_apply_filter('http_default_options_timeout', 3), 'useragent' => yourls_http_user_agent(), 'follow_redirects' => true, 'redirects' => 3);
    if (yourls_http_proxy_is_defined()) {
        if (defined('YOURLS_PROXY_USERNAME') && defined('YOURLS_PROXY_PASSWORD')) {
            $options['proxy'] = array(YOURLS_PROXY, YOURLS_PROXY_USERNAME, YOURLS_PROXY_PASSWORD);
        } else {
            $options['proxy'] = YOURLS_PROXY;
        }
    }
    return yourls_apply_filter('http_default_options', $options);
}
コード例 #2
0
function yourls_get_remote_content_fsockopen($url, $maxlen = 4096, $timeout = 5)
{
    // get the host name and url path
    $parsed_url = parse_url($url);
    $host = $parsed_url['host'];
    if (isset($parsed_url['path'])) {
        $path = $parsed_url['path'];
    } else {
        $path = '/';
        // the url is pointing to the host like http://www.mysite.com
    }
    if (isset($parsed_url['query'])) {
        $path .= '?' . $parsed_url['query'];
    }
    if (isset($parsed_url['port'])) {
        $port = $parsed_url['port'];
    } else {
        $port = '80';
    }
    $response = false;
    // connect to the remote server
    $fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
    var_dump($errno, $errstr);
    if ($fp !== false) {
        // send some fake headers to mimick a standard browser
        fputs($fp, "GET {$path} HTTP/1.0\r\n" . "Host: {$host}\r\n" . "User-Agent: " . yourls_http_user_agent() . "\r\n" . "Accept: */*\r\n" . "Accept-Language: en-us,en;q=0.5\r\n" . "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" . "Keep-Alive: 300\r\n" . "Connection: keep-alive\r\n" . "Referer: http://{$host}\r\n\r\n");
        // retrieve the response from the remote server
        $buffer = min($maxlen, 4096);
        while (!feof($fp) && !(strlen($response) >= $maxlen)) {
            // get more or less $maxlen bytes (between $maxlen and ($maxlen + ($maxlen-1)) actually)
            $response .= fread($fp, $buffer);
        }
        fclose($fp);
    } else {
        //$response = trim( "Error: #$errno. $errstr" );
        return false;
    }
    // return the file content
    return $response;
}
コード例 #3
0
ファイル: functions-http.php プロジェクト: alex-connor/YOURLS
/**
 * Default HTTP requests options for YOURLS
 *
 * For a list of all available options, see function request() in /includes/Requests/Requests.php
 *
 * @since 1.7
 * @return array Options
 */
function yourls_http_default_options()
{
    $options = array('timeout' => yourls_apply_filter('http_default_options_timeout', 3), 'useragent' => yourls_http_user_agent(), 'follow_redirects' => true, 'redirects' => 3);
    if (yourls_http_get_proxy()) {
        $options['proxy'] = yourls_http_get_proxy();
    }
    return yourls_apply_filter('http_default_options', $options);
}